summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-12-18 13:25:09 +0000
committerLaurent Bercot <ska@appnovation.com>2023-12-18 13:25:09 +0000
commit8aae9ebac033ad235ef213c4a3073d7bca9a2611 (patch)
treefd76b96b1ab7e9bfcf7947a86ae2fd1fc06c06c2
parent3c645356e5c92fc5faa77e81fab2f16b11cd6242 (diff)
downloadskalibs-8aae9ebac033ad235ef213c4a3073d7bca9a2611.tar.xz
Don't smash 1 byte 1/8th of the time
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--src/libstddjb/bitarray_clearsetn.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libstddjb/bitarray_clearsetn.c b/src/libstddjb/bitarray_clearsetn.c
index 613a8a8..9198984 100644
--- 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 ;
+ }
}
}