Commit 9683a45f authored by David Gibson's avatar David Gibson Committed by Dan Good

altstack: Don't use 0 pointer literals

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: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent 029a45b8
...@@ -63,8 +63,8 @@ ...@@ -63,8 +63,8 @@
* void *out; * void *out;
* *
* assert(argc == 3); * assert(argc == 3);
* stk_max = strtol(argv[1], 0, 0) * 1024 * 1024; * stk_max = strtol(argv[1], NULL, 0) * 1024 * 1024;
* vla_sz = strtol(argv[2], 0, 0) * 1024 * 1024; * vla_sz = strtol(argv[2], NULL, 0) * 1024 * 1024;
* assert(stk_max > 0 && vla_sz > 0); * assert(stk_max > 0 && vla_sz > 0);
* *
* snprintf(maps, sizeof(maps), "egrep '\\[stack' /proc/%d/maps", getpid()); * snprintf(maps, sizeof(maps), "egrep '\\[stack' /proc/%d/maps", getpid());
......
...@@ -78,10 +78,10 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out) ...@@ -78,10 +78,10 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out)
state.fn = fn; state.fn = fn;
state.arg = arg; state.arg = arg;
state.out = 0; state.out = NULL;
state.max = max; state.max = max;
state.ebuf[state.elen = 0] = '\0'; 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 // 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 // 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) ...@@ -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); ok(setrlimit(RLIMIT_STACK, &(struct rlimit) { state.max, rl_save.rlim_max }), 1);
undo++; 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++; undo++;
if (setjmp(state.jmp) == 0) { if (setjmp(state.jmp) == 0) {
...@@ -130,9 +130,9 @@ out: ...@@ -130,9 +130,9 @@ out:
switch (undo) { switch (undo) {
case 4: case 4:
ok(sigaction(SIGSEGV, &sa_save, 0), 0); ok(sigaction(SIGSEGV, &sa_save, NULL), 0);
case 3: case 3:
ok(sigaltstack(&ss_save, 0), 0); ok(sigaltstack(&ss_save, NULL), 0);
case 2: case 2:
ok(munmap(m, max), 0); ok(munmap(m, max), 0);
case 1: case 1:
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
* static void *wrap(void *i) * static void *wrap(void *i)
* { * {
* dn((unsigned long) i); * dn((unsigned long) i);
* return 0; * return NULL;
* } * }
* *
* #define MiB (1024UL*1024UL) * #define MiB (1024UL*1024UL)
...@@ -60,9 +60,9 @@ ...@@ -60,9 +60,9 @@
* { * {
* unsigned long n; * unsigned long n;
* assert(argc == 2); * 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(); * altstack_perror();
* *
* printf("%d\n", depth); * printf("%d\n", depth);
......
...@@ -87,43 +87,43 @@ int main(void) ...@@ -87,43 +87,43 @@ int main(void)
plan_tests(50); 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,
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_, getrlimit_,
0); 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_, getrlimit_|setrlimit_,
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_, getrlimit_|setrlimit_|mmap_,
setrlimit_|munmap_); 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_,
setrlimit_|munmap_|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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_); setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1) if (fail = 0, munmap(m_, msz_) == -1)
err(1, "munmap"); 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_); setrlimit_|munmap_|sigaltstack_|sigaction_);
// be sure segv catch is repeatable (SA_NODEFER) // 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_); setrlimit_|munmap_|sigaltstack_|sigaction_);
used = 1; 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_); setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1) if (fail = 0, munmap(m_, msz_) == -1)
...@@ -150,7 +150,7 @@ int main(void) ...@@ -150,7 +150,7 @@ int main(void)
ok1(strcmp(buf, estr "\n") == 0); ok1(strcmp(buf, estr "\n") == 0);
used = 1; 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_); setrlimit_|munmap_|sigaltstack_|sigaction_);
...@@ -158,7 +158,7 @@ int main(void) ...@@ -158,7 +158,7 @@ int main(void)
ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz); ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz);
used = 0; 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_, getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_|munmap_,
setrlimit_|munmap_|sigaltstack_|sigaction_); setrlimit_|munmap_|sigaltstack_|sigaction_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment