Mercurial > gnulib
changeset 36938:5868ba6f1d87
sigprocmask-tests: skip test if pid is unexpectedly large
At least mingw64 has 8-byte pid_t but only 4-byte long. Silent
truncation to int in printing a pid value with %d risks killing the
wrong process. But rather than try to futz with determining
the maximum pid_t, it is simpler to just cap things by realizing
that this test is already skipped on mingw64, so adding a sanity
check bounds comparison (and hard-coding the result rather than
dragging in headers for INT_MAX) is just as effective at avoiding
theoretical problems with no real loss in test coverage.
* tests/test-sigprocmask.c (main): Add range check.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Mon, 31 Dec 2012 16:51:29 -0700 |
parents | 01a4e86fc27e |
children | fe1f33aee3cf |
files | ChangeLog tests/test-sigprocmask.c |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Dec 31 16:01:13 2012 -0700 +++ b/ChangeLog Mon Dec 31 16:51:29 2012 -0700 @@ -1,5 +1,8 @@ 2012-12-31 Eric Blake <eblake@redhat.com> + sigprocmask-tests: skip test if pid is unexpectedly large + * tests/test-sigprocmask.c (main): Add range check. + git-version-gen: avoid test -z portability glitch * build-aux/git-version-gen: Prefer portable test spelling, since git-version-gen is run on more than just developer machines.
--- a/tests/test-sigprocmask.c Mon Dec 31 16:01:13 2012 -0700 +++ b/tests/test-sigprocmask.c Mon Dec 31 16:51:29 2012 -0700 @@ -44,9 +44,15 @@ main (int argc, char *argv[]) { sigset_t set; - int pid = getpid (); + pid_t pid = getpid (); char command[80]; + if (sizeof (int) < sizeof pid && 0x7fffffff < pid) + { + fputs ("Skipping test: pid too large\n", stderr); + return 77; + } + signal (SIGINT, sigint_handler); sigemptyset (&set); @@ -60,7 +66,7 @@ ASSERT (sigprocmask (SIG_BLOCK, &set, NULL) == 0); /* Request a SIGINT signal from outside. */ - sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid); + sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid); ASSERT (system (command) == 0); /* Wait. */