From aff09967d194d062ae8d83c0fbe1edf158804ef9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 4 Mar 2016 10:45:10 +0100 Subject: Clean up, fix a few bugs, and add a test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zbset.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/zbset.c') diff --git a/src/zbset.c b/src/zbset.c index d7b7784..c379e2a 100644 --- a/src/zbset.c +++ b/src/zbset.c @@ -5,12 +5,12 @@ void zbset(z_t a, z_t b, size_t bit, int action) { - zahl_char_t x = 1; + zahl_char_t mask = 1; size_t chars; chars = FLOOR_BITS_TO_CHARS(bit); bit = BITS_IN_LAST_CHAR(bit); - x <<= bit; + mask <<= bit; SET(a, b); @@ -20,19 +20,19 @@ zbset(z_t a, z_t b, size_t bit, int action) SET_SIGNUM(a, 1); } if (a->used <= chars) { - if (a->alloced <= chars) - zahl_realloc(a, chars + 1); - zmemset(a->chars + a->used, 0, chars - a->used + 1); + ENSURE_SIZE(a, chars + 1); + zmemset(a->chars + a->used, 0, chars + 1 - a->used); + a->used = chars + 1; } } if (action > 0) { - a->chars[chars] |= x; + a->chars[chars] |= mask; return; } else if (action < 0) { - a->chars[chars] ^= x; - } else if (a->used > chars) { - a->chars[chars] &= ~x; + a->chars[chars] ^= mask; + } else if (chars < a->used) { + a->chars[chars] &= ~mask; } while (a->used && !a->chars[a->used - 1]) -- cgit v1.2.3-70-g09d2