Browse Source

idtree: add unit test for ids around INT_MAX

This causes a SEGV on my laptop.
Rusty Russell 15 years ago
parent
commit
d208258f51
2 changed files with 23 additions and 1 deletions
  1. 22 0
      ccan/idtree/test/run-wrap.c
  2. 1 1
      ccan/idtree/test/run.c

+ 22 - 0
ccan/idtree/test/run-wrap.c

@@ -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());
+}

+ 1 - 1
ccan/idtree/test/run.c

@@ -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[])
 {