]> git.ozlabs.org Git - ccan/commitdiff
idtree: add unit test for ids around INT_MAX
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 6 Dec 2010 02:22:19 +0000 (12:52 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 6 Dec 2010 02:22:19 +0000 (12:52 +1030)
This causes a SEGV on my laptop.

ccan/idtree/test/run-wrap.c [new file with mode: 0644]
ccan/idtree/test/run.c

diff --git a/ccan/idtree/test/run-wrap.c b/ccan/idtree/test/run-wrap.c
new file mode 100644 (file)
index 0000000..6a62323
--- /dev/null
@@ -0,0 +1,22 @@
+#include <ccan/idtree/idtree.c>
+#include <ccan/tap/tap.h>
+#include <limits.h>
+
+int main(int argc, char *argv[])
+{
+       unsigned int i;
+       struct idtree *idtree;
+
+       plan_tests(6);
+       idtree = idtree_new(NULL);
+
+       ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == INT_MAX-1);
+       ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == INT_MAX);
+       ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == -1);
+
+       ok1(idtree_remove(idtree, INT_MAX-1) == true);
+       ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == INT_MAX-1);
+       ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == -1);
+       talloc_free(idtree);
+       exit(exit_status());
+}
index bd12f4c3b2063513f909ddccffc4df015c4d8b12..99ea2daa1d6da512c582c9bf8389ef8b8135b526 100644 (file)
@@ -2,7 +2,7 @@
 #include <ccan/tap/tap.h>
 #include <limits.h>
 
-#define ALLOC_MAX 32
+#define ALLOC_MAX (2 * IDTREE_SIZE)
 
 int main(int argc, char *argv[])
 {