test-strstr: use memory fence, when possible
authorEric Blake <ebb9@byu.net>
Mon, 8 Jun 2009 12:17:39 +0000 (06:17 -0600)
committerEric Blake <ebb9@byu.net>
Mon, 8 Jun 2009 12:34:32 +0000 (06:34 -0600)
* tests/test-strstr.c (main): Use memory fence, in order to be
more likely to trigger Debian bug 521737.
* modules/strstr-tests (Files): Pull in additional files.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
modules/strstr-tests
tests/test-strstr.c

index 729f727..34f4b6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-06-08  Eric Blake  <ebb9@byu.net>
 
+       test-strstr: use memory fence, when possible
+       * tests/test-strstr.c (main): Use memory fence, in order to be
+       more likely to trigger Debian bug 521737.
+       * modules/strstr-tests (Files): Pull in additional files.
+
        memchr: no longer obsolete, for wider field testing
        * modules/memchr (Status, Notice): Delete, this module is no
        longer obsolete.
index 23e67b0..8f09e58 100644 (file)
@@ -1,12 +1,18 @@
 Files:
 tests/test-strstr.c
+tests/zerosize-ptr.h
+m4/mmap-anon.m4
 
 Depends-on:
+extensions
+getpagesize
 
 configure.ac:
 AC_CHECK_DECLS_ONCE([alarm])
+gl_FUNC_MMAP_ANON
+AC_CHECK_HEADERS_ONCE([sys/mman.h])
+AC_CHECK_FUNCS_ONCE([mprotect])
 
 Makefile.am:
 TESTS += test-strstr
 check_PROGRAMS += test-strstr
-
index f7bc4cb..37f4bac 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "zerosize-ptr.h"
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
@@ -68,13 +70,16 @@ main (int argc, char *argv[])
        This is a bug in memchr(), see the Austin Group's clarification
        <http://www.opengroup.org/austin/docs/austin_454.txt>.  */
     const char *fix = "aBaaaaaaaaaaax";
-    char *input = malloc (strlen (fix) + 1);
+    char *page_boundary = (char *) zerosize_ptr ();
+    size_t len = strlen (fix) + 1;
+    char *input = page_boundary ? page_boundary - len : malloc (len);
     const char *result;
 
     strcpy (input, fix);
     result = strstr (input, "B1x");
     ASSERT (result == NULL);
-    free (input);
+    if (!page_boundary)
+      free (input);
   }
 
   {