X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-rawmemchr.c;h=be8feacf9b0daa39606f0ae2f6d8e5266a5a6426;hb=54c55a69f206e114d2bf294363314b226373f445;hp=f1eef2c2785915e73775a09329c1b0ebacb69ca2;hpb=89ae4589dd58d12e7cbcf0e92c1d828c1e430f97;p=gnulib.git diff --git a/tests/test-rawmemchr.c b/tests/test-rawmemchr.c index f1eef2c27..be8feacf9 100644 --- a/tests/test-rawmemchr.c +++ b/tests/test-rawmemchr.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Free Software Foundation + * Copyright (C) 2008-2011 Free Software Foundation, Inc. * Written by Eric Blake and Bruno Haible * * This program is free software: you can redistribute it and/or modify @@ -22,20 +22,10 @@ #include "signature.h" SIGNATURE_CHECK (rawmemchr, void *, (void const *, int)); -#include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "zerosize-ptr.h" +#include "macros.h" /* Calculating void * + int is not portable, so this wrapper converts to char * to make the tests easier to write. */ @@ -64,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); @@ -81,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;