From 8aae9ebac033ad235ef213c4a3073d7bca9a2611 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 18 Dec 2023 13:25:09 +0000 Subject: Don't smash 1 byte 1/8th of the time Signed-off-by: Laurent Bercot --- src/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 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 ; + } } } -- cgit v1.2.3