public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Fix stdio-common tests for GCC 12 -Waddress
@ 2021-10-04 18:42 Joseph Myers
  2021-10-04 18:53 ` Adhemerval Zanella
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Myers @ 2021-10-04 18:42 UTC (permalink / raw)
  To: libc-alpha

My glibc bot shows failures building the testsuite with GCC mainline
across all architectures:

tst-vfprintf-width-prec.c: In function 'do_test':
tst-vfprintf-width-prec.c:90:16: error: the comparison will always evaluate as 'false' for the address of 'result' will never be NULL [-Werror=address]
   90 |     if (result == NULL)
      |                ^~
tst-vfprintf-width-prec.c:89:13: note: 'result' declared here
   89 |     wchar_t result[100];
      |             ^~~~~~

This is clearly a correct warning; the comparison against NULL is
clearly a cut-and-paste mistake from an earlier case in the test that
does use calloc.  Thus, remove the unnecessary check for NULL shown up
by the warning.

Similarly, two other tests have bogus comparisons against NULL; remove
those as well:

scanf14a.c:95:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
   95 |   if (fname == NULL)
      |             ^~
scanf14a.c:93:8: note: 'fname' declared here
   93 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"];
      |        ^~~~~

scanf16a.c:125:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
  125 |   if (fname == NULL)
      |             ^~
scanf16a.c:123:8: note: 'fname' declared here
  123 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"];
      |        ^~~~~

Tested with build-many-glibcs.py (GCC mainline) for aarch64-linux-gnu.

diff --git a/stdio-common/scanf14a.c b/stdio-common/scanf14a.c
index 12adcff5a4..b37712d1c6 100644
--- a/stdio-common/scanf14a.c
+++ b/stdio-common/scanf14a.c
@@ -92,8 +92,6 @@ main (void)
 
   char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"];
   sprintf (fname, "%s/tst-scanf14.XXXXXX", tmpdir);
-  if (fname == NULL)
-    FAIL ();
 
   /* Create a temporary file.   */
   int fd = mkstemp (fname);
diff --git a/stdio-common/scanf16a.c b/stdio-common/scanf16a.c
index 400d85a54e..74d0295c97 100644
--- a/stdio-common/scanf16a.c
+++ b/stdio-common/scanf16a.c
@@ -122,8 +122,6 @@ main (void)
 
   char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"];
   sprintf (fname, "%s/tst-scanf16.XXXXXX", tmpdir);
-  if (fname == NULL)
-    FAIL ();
 
   /* Create a temporary file.   */
   int fd = mkstemp (fname);
diff --git a/stdio-common/tst-vfprintf-width-prec.c b/stdio-common/tst-vfprintf-width-prec.c
index 3192fd797a..278d57f739 100644
--- a/stdio-common/tst-vfprintf-width-prec.c
+++ b/stdio-common/tst-vfprintf-width-prec.c
@@ -87,12 +87,6 @@ do_test (void)
   }
   {
     wchar_t result[100];
-    if (result == NULL)
-      {
-        printf ("error: calloc (%d, %zu): %m", ret + 1, sizeof (wchar_t));
-        return 1;
-      }
-
     ret = swprintf (result, 100, L"%133000.999999999x", 17);
     if (ret >= 0)
       {

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix stdio-common tests for GCC 12 -Waddress
  2021-10-04 18:42 Fix stdio-common tests for GCC 12 -Waddress Joseph Myers
@ 2021-10-04 18:53 ` Adhemerval Zanella
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2021-10-04 18:53 UTC (permalink / raw)
  To: Joseph Myers, libc-alpha



On 04/10/2021 15:42, Joseph Myers wrote:
> My glibc bot shows failures building the testsuite with GCC mainline
> across all architectures:
> 
> tst-vfprintf-width-prec.c: In function 'do_test':
> tst-vfprintf-width-prec.c:90:16: error: the comparison will always evaluate as 'false' for the address of 'result' will never be NULL [-Werror=address]
>    90 |     if (result == NULL)
>       |                ^~
> tst-vfprintf-width-prec.c:89:13: note: 'result' declared here
>    89 |     wchar_t result[100];
>       |             ^~~~~~
> 
> This is clearly a correct warning; the comparison against NULL is
> clearly a cut-and-paste mistake from an earlier case in the test that
> does use calloc.  Thus, remove the unnecessary check for NULL shown up
> by the warning.
> 
> Similarly, two other tests have bogus comparisons against NULL; remove
> those as well:
> 
> scanf14a.c:95:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
>    95 |   if (fname == NULL)
>       |             ^~
> scanf14a.c:93:8: note: 'fname' declared here
>    93 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"];
>       |        ^~~~~
> 
> scanf16a.c:125:13: error: the comparison will always evaluate as 'false' for the address of 'fname' will never be NULL [-Werror=address]
>   125 |   if (fname == NULL)
>       |             ^~
> scanf16a.c:123:8: note: 'fname' declared here
>   123 |   char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"];
>       |        ^~~~~
> 
> Tested with build-many-glibcs.py (GCC mainline) for aarch64-linux-gnu.
> 

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> diff --git a/stdio-common/scanf14a.c b/stdio-common/scanf14a.c
> index 12adcff5a4..b37712d1c6 100644
> --- a/stdio-common/scanf14a.c
> +++ b/stdio-common/scanf14a.c
> @@ -92,8 +92,6 @@ main (void)
>  
>    char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"];
>    sprintf (fname, "%s/tst-scanf14.XXXXXX", tmpdir);
> -  if (fname == NULL)
> -    FAIL ();
>  
>    /* Create a temporary file.   */
>    int fd = mkstemp (fname);
> diff --git a/stdio-common/scanf16a.c b/stdio-common/scanf16a.c
> index 400d85a54e..74d0295c97 100644
> --- a/stdio-common/scanf16a.c
> +++ b/stdio-common/scanf16a.c
> @@ -122,8 +122,6 @@ main (void)
>  
>    char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"];
>    sprintf (fname, "%s/tst-scanf16.XXXXXX", tmpdir);
> -  if (fname == NULL)
> -    FAIL ();
>  
>    /* Create a temporary file.   */
>    int fd = mkstemp (fname);
> diff --git a/stdio-common/tst-vfprintf-width-prec.c b/stdio-common/tst-vfprintf-width-prec.c
> index 3192fd797a..278d57f739 100644
> --- a/stdio-common/tst-vfprintf-width-prec.c
> +++ b/stdio-common/tst-vfprintf-width-prec.c
> @@ -87,12 +87,6 @@ do_test (void)
>    }
>    {
>      wchar_t result[100];
> -    if (result == NULL)
> -      {
> -        printf ("error: calloc (%d, %zu): %m", ret + 1, sizeof (wchar_t));
> -        return 1;
> -      }
> -
>      ret = swprintf (result, 100, L"%133000.999999999x", 17);
>      if (ret >= 0)
>        {
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-04 18:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 18:42 Fix stdio-common tests for GCC 12 -Waddress Joseph Myers
2021-10-04 18:53 ` Adhemerval Zanella

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).