+2020-07-01 Paul Eggert <eggert@cs.ucla.edu>
+
+ tests: pacify gcc -fanalyzer on zerosize_ptr
+ * tests/test-memcasecmp.c (main):
+ * tests/test-memchr.c (main):
+ * tests/test-memchr2.c (main):
+ * tests/test-memcmp.c (main):
+ * tests/test-memmem.c (main):
+ * tests/test-memrchr.c (main):
+ * tests/unistr/test-chr.h (main):
+ * tests/unistr/test-cmp.h (test_cmp):
+ Check whether zerosize_ptr returns NULL before using it.
+ This pacifies GCC 10.1’s new fanalyzer option, and matches
+ other uses of zerosize_ptr.
+
2020-07-01 Bruno Haible <bruno@clisp.org>
asyncsafe-spin: Add tests.
main (void)
{
/* Test equal / not equal distinction. */
- ASSERT (memcasecmp (zerosize_ptr (), zerosize_ptr (), 0) == 0);
+ void *page_boundary1 = zerosize_ptr ();
+ void *page_boundary2 = zerosize_ptr ();
+ if (page_boundary1 && page_boundary2)
+ ASSERT (memcasecmp (page_boundary1, page_boundary2, 0) == 0);
ASSERT (memcasecmp ("foo", "foobar", 2) == 0);
ASSERT (memcasecmp ("foo", "foobar", 3) == 0);
ASSERT (memcasecmp ("foo", "foobar", 4) != 0);
ASSERT (MEMCHR (input, 'a', n) == input);
ASSERT (MEMCHR (input, 'a', 0) == NULL);
- ASSERT (MEMCHR (zerosize_ptr (), 'a', 0) == NULL);
+ void *page_boundary = zerosize_ptr ();
+ if (page_boundary)
+ ASSERT (MEMCHR (page_boundary, 'a', 0) == NULL);
ASSERT (MEMCHR (input, 'b', n) == input + 1);
ASSERT (MEMCHR (input, 'c', n) == input + 2);
ASSERT (MEMCHR2 (input, 'b', 'a', n) == input);
ASSERT (MEMCHR2 (input, 'a', 'b', 0) == NULL);
- ASSERT (MEMCHR2 (zerosize_ptr (), 'a', 'b', 0) == NULL);
+ void *page_boundary = zerosize_ptr ();
+ if (page_boundary)
+ ASSERT (MEMCHR2 (page_boundary, 'a', 'b', 0) == NULL);
ASSERT (MEMCHR2 (input, 'b', 'd', n) == input + 1);
ASSERT (MEMCHR2 (input + 2, 'b', 'd', n - 2) == input + 1026);
int (* volatile memcmp_ptr) (const void *, const void *, size_t) = memcmp;
/* Test equal / not equal distinction. */
- ASSERT (memcmp (zerosize_ptr (), zerosize_ptr (), 0) == 0);
+ void *page_boundary1 = zerosize_ptr ();
+ void *page_boundary2 = zerosize_ptr ();
+ if (page_boundary1 && page_boundary2)
+ ASSERT (memcmp (page_boundary1, page_boundary2, 0) == 0);
ASSERT (memcmp ("foo", "foobar", 2) == 0);
ASSERT (memcmp ("foo", "foobar", 3) == 0);
ASSERT (memcmp ("foo", "foobar", 4) != 0);
}
/* Check that length 0 does not dereference the pointer. */
- {
- const char *result = memmem (zerosize_ptr (), 0, "foo", 3);
- ASSERT (result == NULL);
- }
+ void *page_boundary = zerosize_ptr ();
+ if (page_boundary)
+ {
+ {
+ const char *result = memmem (page_boundary, 0, "foo", 3);
+ ASSERT (result == NULL);
+ }
- {
- const char input[] = "foo";
- const char *result = memmem (input, strlen (input), zerosize_ptr (), 0);
- ASSERT (result == input);
- }
+ {
+ const char input[] = "foo";
+ const char *result = memmem (input, strlen (input), page_boundary, 0);
+ ASSERT (result == input);
+ }
+ }
/* Check that a long periodic needle does not cause false positives. */
{
ASSERT (MEMRCHR (input, 'a', n) == input + n - 1);
ASSERT (MEMRCHR (input, 'a', 0) == NULL);
- ASSERT (MEMRCHR (zerosize_ptr (), 'a', 0) == NULL);
+ void *page_boundary = zerosize_ptr ();
+ if (page_boundary)
+ ASSERT (MEMRCHR (page_boundary, 'a', 0) == NULL);
ASSERT (MEMRCHR (input, 'b', n) == input + n - 2);
ASSERT (MEMRCHR (input, 'c', n) == input + n - 3);
ASSERT (U_CHR (input, length, 'a') == input);
ASSERT (U_CHR (input, 0, 'a') == NULL);
- ASSERT (U_CHR (zerosize_ptr (), 0, 'a') == NULL);
+ void *page_boundary = zerosize_ptr ();
+ if (page_boundary)
+ ASSERT (U_CHR (page_boundary, 0, 'a') == NULL);
ASSERT (U_CHR (input, length, 'b') == input + 1);
ASSERT (U_CHR (input, length, 'c') == input + 2);
test_cmp (void)
{
/* Test equal / not equal distinction. */
- ASSERT (U_CMP (zerosize_ptr (), zerosize_ptr (), 0) == 0);
+ void *page_boundary1 = zerosize_ptr ();
+ void *page_boundary2 = zerosize_ptr ();
+ if (page_boundary1 && page_boundary2)
+ ASSERT (U_CMP (page_boundary1, page_boundary2, 0) == 0);
{
static const UNIT input1[] = { 'f', 'o', 'o', 0 };
static const UNIT input2[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };