c-stack: Expose false positives when not using libsigsegv.
authorEric Blake <ebb9@byu.net>
Wed, 16 Jul 2008 22:28:13 +0000 (16:28 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 17 Jul 2008 02:55:57 +0000 (20:55 -0600)
* modules/c-stack-tests (Files): Expand test.
* tests/test-c-stack.c (main): Add means to conditionally trigger
non-overflow SIGSEGV.
* tests/test-c-stack2.sh: New file.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
modules/c-stack-tests
tests/test-c-stack.c
tests/test-c-stack2.sh [new file with mode: 0755]

index 91c45ce..0772f2d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,18 @@
+2008-07-16  Eric Blake  <ebb9@byu.net>
+
+       c-stack: Expose false positives when not using libsigsegv.
+       * modules/c-stack-tests (Files): Expand test.
+       * tests/test-c-stack.c (main): Add means to conditionally trigger
+       non-overflow SIGSEGV.
+       * tests/test-c-stack2.sh: New file.
+
 2008-07-14  Bruno Haible  <bruno@clisp.org>
 
        * m4/libsigsegv.m4: Remove unneeded AC_PREREQ.
        Reported by Eric Blake.
 
 2008-07-14  Sam Steingold  <sds@gnu.org>
-            Bruno Haible  <bruno@clisp.org>
+           Bruno Haible  <bruno@clisp.org>
 
        New module libsigsegv.
        * modules/libsigsegv: New file.
index 291f58d..5d3bc58 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-c-stack.c
 tests/test-c-stack.sh
+tests/test-c-stack2.sh
 
 Depends-on:
 exitfail
@@ -8,8 +9,8 @@ exitfail
 configure.ac:
 
 Makefile.am:
-TESTS += test-c-stack.sh
+TESTS += test-c-stack.sh test-c-stack2.sh
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
 check_PROGRAMS += test-c-stack
 test_c_stack_LDADD = $(LDADD) @LIBINTL@
-MOSTLYCLEANFILES += t-c-stack.tmp
+MOSTLYCLEANFILES += t-c-stack.tmp t-c-stack2.tmp
index 13c1a12..bcf72ad 100644 (file)
   do                                                                        \
     {                                                                       \
       if (!(expr))                                                          \
-        {                                                                   \
-          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
-          fflush (stderr);                                                  \
-          abort ();                                                         \
-        }                                                                   \
+                                                                          \
+         fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+         fflush (stderr);                                                   \
+         abort ();                                                          \
+                                                                          \
     }                                                                       \
   while (0)
 
@@ -62,7 +62,14 @@ main (int argc, char **argv)
 #endif
 
   if (c_stack_action (0) == 0)
-    return recurse ("\1");
+    {
+      if (1 < argc)
+       {
+         exit_failure = 77;
+         ++*argv[argc]; /* Intentionally dereference NULL.  */
+       }
+      return recurse ("\1");
+    }
   perror ("c_stack_action");
   return 77;
 }
diff --git a/tests/test-c-stack2.sh b/tests/test-c-stack2.sh
new file mode 100755 (executable)
index 0000000..e55ff17
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-c-stack2.tmp"
+
+# Sanitize exit status within a subshell, since some shells fail to
+# redirect stderr on their message about death due to signal.
+(./test-c-stack${EXEEXT} 1; exit $?) 2> t-c-stack2.tmp
+
+case $? in
+  77) if grep 'stack overflow' t-c-stack2.tmp >/dev/null ; then
+       echo 'cannot distinguish stack overflow from crash' >&2
+      else
+       cat t-c-stack2.tmp >&2
+      fi
+      (exit 77); exit 77 ;;
+  0) (exit 1); exit 1 ;;
+esac
+if grep 'program error' t-c-stack2.tmp >/dev/null ; then
+  :
+else
+  (exit 1); exit 1
+fi
+
+rm -fr $tmpfiles
+
+exit 0