altstack: Don't use 0 pointer literals
authorDavid Gibson <david@gibson.dropbear.id.au>
Fri, 3 Jun 2016 08:42:02 +0000 (18:42 +1000)
committerDan Good <dan@dancancode.com>
Thu, 16 Jun 2016 20:18:52 +0000 (20:18 +0000)
In a number of places the altstack module uses a literal '0' for pointer
values.  That's correct C, but doesn't make it obvious on a quick read
whether values are integers or pointers.  This patch changes those cases
to use the NULL define instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/altstack/_info
ccan/altstack/altstack.c
ccan/altstack/altstack.h
ccan/altstack/test/run.c

index 7accf8648108841b7f42e0fb9f97e8d5a9e919e6..b8cf6a87769afe692aa8fd5a1fc1b0d7691ed48e 100644 (file)
@@ -63,8 +63,8 @@
  *             void *out;
  *
  *             assert(argc == 3);
- *             stk_max = strtol(argv[1], 0, 0) * 1024 * 1024;
- *             vla_sz  = strtol(argv[2], 0, 0) * 1024 * 1024;
+ *             stk_max = strtol(argv[1], NULL, 0) * 1024 * 1024;
+ *             vla_sz  = strtol(argv[2], NULL, 0) * 1024 * 1024;
  *             assert(stk_max > 0 && vla_sz > 0);
  *
  *             snprintf(maps, sizeof(maps), "egrep '\\[stack' /proc/%d/maps", getpid());
index 62db343cb2c9523a2d4ba11002c27d83c87ac43e..afee46e8a619c3d77c963f58feda7560e9debeb1 100644 (file)
@@ -78,10 +78,10 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out)
 
        state.fn  = fn;
        state.arg = arg;
-       state.out = 0;
+       state.out = NULL;
        state.max = max;
        state.ebuf[state.elen = 0] = '\0';
-       if (out) *out = 0;
+       if (out) *out = NULL;
 
        // if the first page below the mapping is in use, we get max-pgsz usable bytes
        // add pgsz to max to guarantee at least max usable bytes
@@ -91,7 +91,7 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out)
        ok(setrlimit(RLIMIT_STACK, &(struct rlimit) { state.max, rl_save.rlim_max }), 1);
        undo++;
 
-       ok(m = mmap(0, max, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN|MAP_NORESERVE, -1, 0), 1);
+       ok(m = mmap(NULL, max, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN|MAP_NORESERVE, -1, 0), 1);
        undo++;
 
        if (setjmp(state.jmp) == 0) {
@@ -130,9 +130,9 @@ out:
 
        switch (undo) {
        case 4:
-               ok(sigaction(SIGSEGV, &sa_save, 0), 0);
+               ok(sigaction(SIGSEGV, &sa_save, NULL), 0);
        case 3:
-               ok(sigaltstack(&ss_save, 0), 0);
+               ok(sigaltstack(&ss_save, NULL), 0);
        case 2:
                ok(munmap(m, max), 0);
        case 1:
index 4445a2a3e5563e74a1f4e6de4cb32bef725691ac..09ffe0b056b504ba99f5e8f176e6ceb9d5f14f52 100644 (file)
@@ -52,7 +52,7 @@
  *     static void *wrap(void *i)
  *     {
  *             dn((unsigned long) i);
- *             return 0;
+ *             return NULL;
  *     }
  *
  *     #define MiB (1024UL*1024UL)
@@ -60,9 +60,9 @@
  *     {
  *             unsigned long n;
  *             assert(argc == 2);
- *             n = strtoul(argv[1], 0, 0);
+ *             n = strtoul(argv[1], NULL, 0);
  *
- *             if (altstack(32*MiB, wrap, (void *) n, 0) != 0)
+ *             if (altstack(32*MiB, wrap, (void *) n, NULL) != 0)
  *                     altstack_perror();
  *
  *             printf("%d\n", depth);
index 61710fda3b9c8dbddab5318ad55caf8aa7d023f6..e109ccbd19be1f88a3c058028a5568ede883dfcf 100644 (file)
@@ -87,43 +87,43 @@ int main(void)
 
        plan_tests(50);
 
-       chkfail(getrlimit_,     altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(getrlimit_),
+       chkfail(getrlimit_,     altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(getrlimit_),
                0,
                0);
 
-       chkfail(setrlimit_,     altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(setrlimit_),
+       chkfail(setrlimit_,     altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(setrlimit_),
                getrlimit_,
                0);
 
-       chkfail(mmap_,          altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(mmap_),
+       chkfail(mmap_,          altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(mmap_),
                getrlimit_|setrlimit_,
                setrlimit_);
 
-       chkfail(sigaltstack_,   altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaltstack_),
+       chkfail(sigaltstack_,   altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaltstack_),
                getrlimit_|setrlimit_|mmap_,
                setrlimit_|munmap_);
 
-       chkfail(sigaction_,     altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaction_),
+       chkfail(sigaction_,     altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaction_),
                getrlimit_|setrlimit_|mmap_|sigaltstack_,
                setrlimit_|munmap_|sigaltstack_);
 
-       chkfail(munmap_,        altstack(8*MiB, wrap, int2ptr(0), 0) ==  1, e(munmap_),
+       chkfail(munmap_,        altstack(8*MiB, wrap, int2ptr(0), NULL) ==  1, e(munmap_),
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
                setrlimit_|sigaltstack_|sigaction_);
        if (fail = 0, munmap(m_, msz_) == -1)
                err(1, "munmap");
 
-       chkok(                  altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
+       chkok(                  altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW,
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
                setrlimit_|munmap_|sigaltstack_|sigaction_);
 
        // be sure segv catch is repeatable (SA_NODEFER)
-       chkok(                  altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
+       chkok(                  altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW,
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
                setrlimit_|munmap_|sigaltstack_|sigaction_);
 
        used = 1;
-       chkfail(munmap_,        altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
+       chkfail(munmap_,        altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW,
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
                setrlimit_|sigaltstack_|sigaction_);
        if (fail = 0, munmap(m_, msz_) == -1)
@@ -150,7 +150,7 @@ int main(void)
        ok1(strcmp(buf, estr "\n") == 0);
 
        used = 1;
-       chkok(                  altstack(8*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
+       chkok(                  altstack(8*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW,
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
                setrlimit_|munmap_|sigaltstack_|sigaction_);
 
@@ -158,7 +158,7 @@ int main(void)
        ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz);
 
        used = 0;
-       chkok(                  altstack(8*MiB, wrap, int2ptr(100000), 0) == 0, 0,
+       chkok(                  altstack(8*MiB, wrap, int2ptr(100000), NULL) == 0, 0,
                getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_|munmap_,
                setrlimit_|munmap_|sigaltstack_|sigaction_);