* [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr
@ 2020-07-01 23:48 Paul Eggert
2020-07-02 21:37 ` Bernhard Voelker
0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2020-07-01 23:48 UTC (permalink / raw)
To: bug-gnulib; +Cc: Paul Eggert
* 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.
---
ChangeLog | 15 +++++++++++++++
tests/test-memcasecmp.c | 5 ++++-
tests/test-memchr.c | 4 +++-
tests/test-memchr2.c | 4 +++-
tests/test-memcmp.c | 5 ++++-
tests/test-memmem.c | 22 +++++++++++++---------
tests/test-memrchr.c | 4 +++-
tests/unistr/test-chr.h | 4 +++-
tests/unistr/test-cmp.h | 5 ++++-
9 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3cde29456..edb63b348 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
diff --git a/tests/test-memcasecmp.c b/tests/test-memcasecmp.c
index 00df2f7cf..33507dc23 100644
--- a/tests/test-memcasecmp.c
+++ b/tests/test-memcasecmp.c
@@ -28,7 +28,10 @@ int
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);
diff --git a/tests/test-memchr.c b/tests/test-memchr.c
index ab8d2c0da..d81bf3baf 100644
--- a/tests/test-memchr.c
+++ b/tests/test-memchr.c
@@ -49,7 +49,9 @@ main (void)
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);
diff --git a/tests/test-memchr2.c b/tests/test-memchr2.c
index 47428f215..8d5478919 100644
--- a/tests/test-memchr2.c
+++ b/tests/test-memchr2.c
@@ -48,7 +48,9 @@ main (void)
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);
diff --git a/tests/test-memcmp.c b/tests/test-memcmp.c
index eaaac4531..5b262aae7 100644
--- a/tests/test-memcmp.c
+++ b/tests/test-memcmp.c
@@ -31,7 +31,10 @@ main (void)
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);
diff --git a/tests/test-memmem.c b/tests/test-memmem.c
index 1c1e0ad39..132265f12 100644
--- a/tests/test-memmem.c
+++ b/tests/test-memmem.c
@@ -73,16 +73,20 @@ main (int argc, char *argv[])
}
/* 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. */
{
diff --git a/tests/test-memrchr.c b/tests/test-memrchr.c
index 001134bb2..235fb6948 100644
--- a/tests/test-memrchr.c
+++ b/tests/test-memrchr.c
@@ -49,7 +49,9 @@ main (void)
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);
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index b67be4886..f60610f22 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -48,7 +48,9 @@ main (void)
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);
diff --git a/tests/unistr/test-cmp.h b/tests/unistr/test-cmp.h
index 38a5223f7..207c59a77 100644
--- a/tests/unistr/test-cmp.h
+++ b/tests/unistr/test-cmp.h
@@ -20,7 +20,10 @@ static void
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 };
--
2.26.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr
2020-07-01 23:48 [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr Paul Eggert
@ 2020-07-02 21:37 ` Bernhard Voelker
2020-07-05 9:14 ` Paul Eggert
0 siblings, 1 reply; 4+ messages in thread
From: Bernhard Voelker @ 2020-07-02 21:37 UTC (permalink / raw)
To: Paul Eggert, bug-gnulib
[-- Attachment #1: Type: text/plain, Size: 833 bytes --]
On 2020-07-02 01:48, Paul Eggert wrote:
> diff --git a/tests/test-memchr.c b/tests/test-memchr.c
> - ASSERT (MEMCHR (zerosize_ptr (), 'a', 0) == NULL);
> + void *page_boundary = zerosize_ptr ();
> + if (page_boundary)
> + ASSERT (MEMCHR (page_boundary, 'a', 0) == NULL);
This triggers a new shadowing warning (here with -Werror, gcc 10.1.1):
test-memchr.c: In function 'main':
test-memchr.c:98:11: error: declaration of 'page_boundary' shadows a previous local [-Werror=shadow]
98 | char *page_boundary = (char *) zerosize_ptr ();
| ^~~~~~~~~~~~~
test-memchr.c:52:9: note: shadowed declaration is here
52 | void *page_boundary = zerosize_ptr ();
| ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
The attached fixes it.
Okay to push?
Have a nice day,
Berny
[-- Attachment #2: 0001-tests-avoid-shadowing-warning.patch --]
[-- Type: text/x-patch, Size: 1408 bytes --]
From c24438ea3d142267f9e5e14440ffe4fa6052f075 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Thu, 2 Jul 2020 23:11:52 +0200
Subject: [PATCH] tests: avoid shadowing warning
* tests/test-memchr.c (main): Give page_boundary variable a tight scope.
---
ChangeLog | 5 +++++
tests/test-memchr.c | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6115ab946..047a3bbd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-07-02 Bernhard Voelker <mail@bernhard-voelker.de>
+
+ tests: avoid shadowing warning
+ * tests/test-memchr.c (main): Give page_boundary variable a tight scope.
+
2020-07-01 Paul Eggert <eggert@cs.ucla.edu>
manywarnings: improve port to GCC 10.1
diff --git a/tests/test-memchr.c b/tests/test-memchr.c
index d81bf3baf..5ea4c03b0 100644
--- a/tests/test-memchr.c
+++ b/tests/test-memchr.c
@@ -49,9 +49,12 @@ main (void)
ASSERT (MEMCHR (input, 'a', n) == input);
ASSERT (MEMCHR (input, 'a', 0) == NULL);
- void *page_boundary = zerosize_ptr ();
- if (page_boundary)
- ASSERT (MEMCHR (page_boundary, '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);
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr
2020-07-02 21:37 ` Bernhard Voelker
@ 2020-07-05 9:14 ` Paul Eggert
2020-07-05 11:21 ` Bernhard Voelker
0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2020-07-05 9:14 UTC (permalink / raw)
To: Bernhard Voelker, bug-gnulib
On 7/2/20 2:37 PM, Bernhard Voelker wrote:
> The attached fixes it.
> Okay to push?
Thanks, looks good.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr
2020-07-05 9:14 ` Paul Eggert
@ 2020-07-05 11:21 ` Bernhard Voelker
0 siblings, 0 replies; 4+ messages in thread
From: Bernhard Voelker @ 2020-07-05 11:21 UTC (permalink / raw)
To: Paul Eggert, bug-gnulib
On 2020-07-05 11:14, Paul Eggert wrote:
> On 7/2/20 2:37 PM, Bernhard Voelker wrote:
>> The attached fixes it.
>> Okay to push?
>
> Thanks, looks good.
Thanks, pushed.
Have a nice day,
Berny
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-05 11:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 23:48 [PATCH] tests: pacify gcc -fanalyzer on zerosize_ptr Paul Eggert
2020-07-02 21:37 ` Bernhard Voelker
2020-07-05 9:14 ` Paul Eggert
2020-07-05 11:21 ` Bernhard Voelker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).