[PATCH 1/8] xfsprogs: Fix setbitval() bug when nbits is byte-aligned

Alex Elder
2011-11-10T20:35:40Z

From: Kevan Rehm <kfr@sgi.com>

If a field whose size is not an even multiple of 8 bits happens to
be aligned on a byte boundary and the machine is little-endian,
routine setbitval() would do a byte copy of zero bytes, effectively
doing nothing.

Catch this case, and arrange for doing the bit setting "the hard
way" (i.e., without using memcpy()) to avoid this problem.

Signed-off-by: Alex Elder <aelder@sgi.com>
---
db/bit.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/db/bit.c b/db/bit.c
index ca57d31..36de0a1 100644
--- a/db/bit.c
+++ b/db/bit.c
@@ -153,7 +153,7 @@ setbitval(
*/

/* byte aligned ? */
- if (bitoff%NBBY) {
+ if (bitoff % NBBY || nbits % NBBY) {
/* no - bit copy */
for (bit=0; bit<nbits; bit++)
setbit(out, bit+bitoff, getbit(in, bit));
--
1.7.6.4