]> git.ozlabs.org Git - ccan/blobdiff - ccan/alloc/test/run-corrupt.c
alloc: fix case where poolsize is not a power of 2.
[ccan] / ccan / alloc / test / run-corrupt.c
diff --git a/ccan/alloc/test/run-corrupt.c b/ccan/alloc/test/run-corrupt.c
new file mode 100644 (file)
index 0000000..3e7be17
--- /dev/null
@@ -0,0 +1,26 @@
+/* Example allocation which caused corruption. */
+#include <ccan/alloc/alloc.c>
+#include <ccan/alloc/bitops.c>
+#include <ccan/alloc/tiny.c>
+#include <ccan/tap/tap.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+       void *mem;
+
+       plan_tests(7);
+
+       mem = malloc(1179648);
+       alloc_init(mem, 1179648);
+       ok1(alloc_check(mem, 1179648));
+       ok1(alloc_get(mem, 1179648, 48, 16));
+       ok1(alloc_check(mem, 1179648));
+       ok1(alloc_get(mem, 1179648, 53, 16));
+       ok1(alloc_check(mem, 1179648));
+       ok1(alloc_get(mem, 1179648, 53, 16));
+       ok1(alloc_check(mem, 1179648));
+       free(mem);
+
+       return exit_status();
+}