]> git.ozlabs.org Git - ccan/blobdiff - ccan/intmap/test/run-order.c
io: fix another leak path for always array.
[ccan] / ccan / intmap / test / run-order.c
index 1b2fdffdfadcb68eeadebe547ae5c9510bebcc11..f7e86692a83647bfaac224dd24495511b4880096 100644 (file)
@@ -7,12 +7,23 @@
 typedef UINTMAP(unsigned int *) umap;
 typedef SINTMAP(int *) smap;
 
+static bool uint_iterate_check(intmap_index_t i, unsigned int *v, int64_t *prev)
+{
+       if ((int64_t)i <= *prev)
+               return false;
+       if (*v != i)
+               return false;
+       *prev = i;
+       return true;
+}
+
 static bool check_umap(const umap *map)
 {
        /* This is a larger type than unsigned, and allows negative */
        int64_t prev;
-       uint64_t i;
+       uint64_t i, last_idx;
        unsigned int *v;
+       bool last = true;
 
        /* Must be in order, must contain value. */
        prev = -1;
@@ -22,15 +33,32 @@ static bool check_umap(const umap *map)
                if (*v != i)
                        return false;
                prev = i;
+               last = (uintmap_last(map, &last_idx) == v);
        }
+
+       if (!last)
+               return false;
+
+       prev = -1;
+       return uintmap_iterate(map, uint_iterate_check, &prev);
+}
+
+static bool sint_iterate_check(sintmap_index_t i, int *v, int64_t *prev)
+{
+       if (i <= *prev)
+               return false;
+       if (*v != i)
+               return false;
+       *prev = i;
        return true;
 }
 
 static bool check_smap(const smap *map)
 {
        /* This is a larger type than int, and allows negative */
-       int64_t prev, i;
+       int64_t prev, i, last_idx;
        int *v;
+       bool last = true;
 
        /* Must be in order, must contain value. */
        prev = -0x80000001ULL;
@@ -39,9 +67,15 @@ static bool check_smap(const smap *map)
                        return false;
                if (*v != i)
                        return false;
+               last = (sintmap_last(map, &last_idx) == v);
                prev = i;
        }
-       return true;
+
+       if (!last)
+               return false;
+
+       prev = -1;
+       return sintmap_iterate(map, sint_iterate_check, &prev);
 }
 
 int main(void)