changeset 11611:ae5773856cba

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. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 08 Jun 2009 06:17:39 -0600
parents 875d8b7f8146
children 991284aa5fe0
files ChangeLog modules/strstr-tests tests/test-strstr.c
diffstat 3 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/modules/strstr-tests
+++ b/modules/strstr-tests
@@ -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
-
--- a/tests/test-strstr.c
+++ b/tests/test-strstr.c
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "zerosize-ptr.h"
+
 #define ASSERT(expr) \
   do									     \
     {									     \
@@ -68,13 +70,16 @@
        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);
   }
 
   {