diff options
author | Eric Blake <eblake@redhat.com> | 2010-09-14 16:42:39 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2010-09-14 16:55:31 -0600 |
commit | 349a6770a685fe472f1c3c4084eebc17d4e5ff5e (patch) | |
tree | fabc3701fbdd7569c9019b3fd92091c6c83db261 /tests/test-rawmemchr.c | |
parent | 017b0b20b432df707718a19443d9435870f0b3c7 (diff) | |
download | gnulib-349a6770a685fe472f1c3c4084eebc17d4e5ff5e.tar.gz |
test-rawmemchr: make more robust
* modules/rawmemchr-tests (Files): Add zerosize-ptr.h, mmap-anon.m4.
(Depends-on, configure.ac): Add needed prerequisites to use it.
* modules/memchr-tests (Files, Depends-on, configure.ac):
Likewise, to avoid implicit reliance on memchr module prereqs.
* tests/test-memchr.c (main): Ensure proper masking.
* tests/test-rawmemchr.c (main): Likewise. Detect oversized
reads.
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests/test-rawmemchr.c')
-rw-r--r-- | tests/test-rawmemchr.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test-rawmemchr.c b/tests/test-rawmemchr.c index 94768183e0..804e15780a 100644 --- a/tests/test-rawmemchr.c +++ b/tests/test-rawmemchr.c @@ -24,6 +24,7 @@ SIGNATURE_CHECK (rawmemchr, void *, (void const *, int)); #include <stdlib.h> +#include "zerosize-ptr.h" #include "macros.h" /* Calculating void * + int is not portable, so this wrapper converts @@ -53,6 +54,7 @@ main (void) ASSERT (RAWMEMCHR (input + 1, 'a') == input + n - 1); ASSERT (RAWMEMCHR (input + 1, 'e') == input + n - 2); + ASSERT (RAWMEMCHR (input + 1, 0x789abc00 | 'e') == input + n - 2); ASSERT (RAWMEMCHR (input, '\0') == input + n); @@ -70,6 +72,20 @@ main (void) } } + /* Ensure that no unaligned oversized reads occur. */ + { + char *page_boundary = (char *) zerosize_ptr (); + size_t i; + + if (!page_boundary) + page_boundary = input + 4096; + memset (page_boundary - 512, '1', 511); + page_boundary[-1] = '2'; + for (i = 1; i <= 512; i++) + ASSERT (RAWMEMCHR (page_boundary - i, (i * 0x01010100) | '2') + == page_boundary - 1); + } + free (input); return 0; |