skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 8aae9ebac033ad235ef213c4a3073d7bca9a2611
parent 3c645356e5c92fc5faa77e81fab2f16b11cd6242
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Mon, 18 Dec 2023 13:25:09 +0000

 Don't smash 1 byte 1/8th of the time

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Msrc/libstddjb/bitarray_clearsetn.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/libstddjb/bitarray_clearsetn.c b/src/libstddjb/bitarray_clearsetn.c @@ -18,7 +18,10 @@ void bitarray_clearsetn (unsigned char *s, size_t a, size_t b, int h) if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; mask = h ? 0xff : 0x00 ; for (; i < b>>3 ; i++) s[i] = mask ; - mask = (1 << (b & 7)) - 1 ; - if (h) s[b>>3] |= mask ; else s[b>>3] &= ~mask ; + if (b & 7) + { + mask = (1 << (b & 7)) - 1 ; + if (h) s[b>>3] |= mask ; else s[b>>3] &= ~mask ; + } } }