]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/test/run-set_alloc.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / opt / test / run-set_alloc.c
index b30a77d8fc552aa8c293ee303f62081c7fab60a8..2d7410ae22853e6bb9fbe6c3896c58dc01773a5c 100644 (file)
@@ -2,15 +2,15 @@
 #include <stdlib.h>
 
 /* Make sure we override these! */
 #include <stdlib.h>
 
 /* Make sure we override these! */
-static void *no_malloc(size_t size)
+static void *no_malloc(size_t size UNNEEDED)
 {
        abort();
 }
 {
        abort();
 }
-static void *no_realloc(void *p, size_t size)
+static void *no_realloc(void *p UNNEEDED, size_t size UNNEEDED)
 {
        abort();
 }
 {
        abort();
 }
-static void no_free(void *p)
+static void no_free(void *p UNNEEDED)
 {
        abort();
 }
 {
        abort();
 }
@@ -59,15 +59,16 @@ static void *reallocfn(void *ptr, size_t size)
 static void freefn(void *ptr)
 {
        free_count++;
 static void freefn(void *ptr)
 {
        free_count++;
-       free(ptr);
        *find_ptr(ptr) = NULL;
        *find_ptr(ptr) = NULL;
+       free(ptr);
 }
 
 int main(int argc, char *argv[])
 {
        const char *myname = argv[0];
 }
 
 int main(int argc, char *argv[])
 {
        const char *myname = argv[0];
+       unsigned int val;
 
 
-       plan_tests(220);
+       plan_tests(222);
 
        opt_set_alloc(allocfn, reallocfn, freefn);
 
 
        opt_set_alloc(allocfn, reallocfn, freefn);
 
@@ -341,6 +342,12 @@ int main(int argc, char *argv[])
        ok1(strcmp(argv[4], "-a") == 0);
        ok1(!argv[5]);
 
        ok1(strcmp(argv[4], "-a") == 0);
        ok1(!argv[5]);
 
+       /* Finally, test the helpers don't use malloc. */
+       reset_options();
+       opt_register_arg("-a", opt_set_uintval, opt_show_uintval, &val, "a");
+       ok1(!parse_args(&argc, &argv, "-a", "notanumber", NULL));
+       ok1(strstr(err_output, ": -a: 'notanumber' is not a number"));
+
        /* We should have tested each one at least once! */
        ok1(realloc_count);
        ok1(alloc_count);
        /* We should have tested each one at least once! */
        ok1(realloc_count);
        ok1(alloc_count);