From 978e8ac39f8ba2d694031e521511da1ae803ccfc Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 11 May 2020 11:29:39 -0600 Subject: Suppress GCC 10 true positive warnings [BZ #25967] Suppress or avoid warnings in tests that exercise failure modes by making calls with invalid arguments. Reviewed-by: DJ Delorie Reviewed-by: Florian Weimer Reviewed-by: Joseph Myers --- io/tst-getcwd.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'io') diff --git a/io/tst-getcwd.c b/io/tst-getcwd.c index 75ecd2c..c9c4713 100644 --- a/io/tst-getcwd.c +++ b/io/tst-getcwd.c @@ -23,6 +23,7 @@ #include #include #include +#include #define TEST_FUNCTION do_test () @@ -58,7 +59,13 @@ do_test (void) bufs[i] = (char *) malloc (sbs); } + /* Avoid warnings about the first argument being null when the second + is nonzero. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (10.1, "-Wnonnull"); bufs[i] = getcwd (NULL, sbs); + DIAG_POP_NEEDS_COMMENT; + lens[i] = sbs; if (bufs[i] == NULL) { @@ -96,12 +103,17 @@ getcwd (NULL, sbs) = \"%s\", getcwd (thepath, sizeof thepath) = \"%s\"\n", free (bufs[i]); /* Test whether the function signals success despite the buffer - being too small. */ + being too small. + Avoid warnings about the first argument being null when the second + is nonzero. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (10.1, "-Wnonnull"); if (getcwd (NULL, len) != NULL) { puts ("getcwd (NULL, len) didn't failed"); return 1; } + DIAG_POP_NEEDS_COMMENT; bufs[0] = malloc (len); bufs[1] = malloc (len); @@ -132,13 +144,18 @@ getcwd (NULL, sbs) = \"%s\", getcwd (thepath, sizeof thepath) = \"%s\"\n", return 1; } - /* Now test handling of correctly sized buffers. */ + /* Now test handling of correctly sized buffers. + Again. avoid warnings about the first argument being null when + the second is nonzero. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (10.1, "-Wnonnull"); bufs[0] = getcwd (NULL, len + 1); if (bufs[0] == NULL) { puts ("getcwd (NULL, len + 1) failed"); return 1; } + DIAG_POP_NEEDS_COMMENT; free (bufs[0]); memset (thepath, '\xff', sizeof thepath); -- cgit v1.1