aboutsummaryrefslogtreecommitdiffstats
path: root/src/zbset.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-04 10:45:10 +0100
committerMattias Andrée <maandree@kth.se>2016-03-04 10:47:53 +0100
commitaff09967d194d062ae8d83c0fbe1edf158804ef9 (patch)
tree793f32bc01e780bb6457570f9ea7a8e7ff94f7bb /src/zbset.c
parentAdd makefile and fix errors (diff)
downloadlibzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.gz
libzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.bz2
libzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.xz
Clean up, fix a few bugs, and add a test
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zbset.c')
-rw-r--r--src/zbset.c18
1 files changed, 9 insertions, 9 deletions
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])