From: Eric Blake Date: Mon, 31 Dec 2012 23:51:29 +0000 (-0700) Subject: sigprocmask-tests: skip test if pid is unexpectedly large X-Git-Tag: v0.1~282 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=e62439a54a711bbaeee685fc058ebc876cc7650e 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 --- diff --git a/ChangeLog b/ChangeLog index 41fc6ac8f..df7999ee5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-12-31 Eric Blake + 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. diff --git a/tests/test-sigprocmask.c b/tests/test-sigprocmask.c index 55d11b0cd..7c1af4f55 100644 --- a/tests/test-sigprocmask.c +++ b/tests/test-sigprocmask.c @@ -44,9 +44,15 @@ int 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 @@ main (int argc, char *argv[]) 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. */