summaryrefslogtreecommitdiffhomepage
path: root/test/bitbuf.test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/bitbuf.test.c')
-rw-r--r--test/bitbuf.test.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/test/bitbuf.test.c b/test/bitbuf.test.c
index 324a7f6..554d3a2 100644
--- a/test/bitbuf.test.c
+++ b/test/bitbuf.test.c
@@ -15,15 +15,11 @@ static union {
static struct bitbuf bb = {bb_buf.buf, 512, 512 * 8, 0, false, false, "test"};
TEST("The possible UB in bitbuf_appendbuf shouldn't trigger horrible bugs") {
- char unalign[3] = {'X', 'X', 'X'};
- char _buf[32 + sizeof(bitbuf_cell)];
- char *buf = _buf;
- if (bitbuf_align <= 1) {
- // *shouldn't* happen
+ if (bitbuf_align <= 1) { // *shouldn't* happen
fputs("what's going on with the alignment???\n", stderr);
return false;
}
- // make sure the pointer is definitely misaligned
+ char _buf[32 + _Alignof(bitbuf_cell)], *buf = _buf;
while (!((usize)buf % bitbuf_align)) ++buf;
memcpy(buf, "Misaligned test buffer contents!", 32);
@@ -31,4 +27,18 @@ TEST("The possible UB in bitbuf_appendbuf shouldn't trigger horrible bugs") {
return !memcmp(bb.buf, buf, 32);
}
+TEST("Aligning to the next byte should work as intended") {
+ for (int i = 0; i < 65535; i += 8) {
+ bb.curbit = i;
+ bitbuf_roundup(&bb);
+ if (bb.curbit != i) return false; // don't round if already rounded
+ for (int j = i + 1; j < i + 8; ++j) {
+ bb.curbit = j;
+ bitbuf_roundup(&bb);
+ if (bb.curbit != i + 8) return false;
+ }
+ }
+ return true;
+}
+
// vi: sw=4 ts=4 noet tw=80 cc=80