Fix gcc 9 build errors for make xcheck.

Message ID b982a153-3685-bf3f-8b14-77402a099f7e@linux.ibm.com
State New
Headers show
Series
  • Fix gcc 9 build errors for make xcheck.
Related show

Commit Message

Stefan Liebler June 17, 2019, 6:35 a.m.
Hi,

this patch fixes the following gcc 9 warnings for "make xcheck":
-string/tst-strcasestr.c:
../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive 
argument is null [-Werror=format-overflow=]

-argp/argp-test.c:
argp-test.c:130:20: error: ‘%d’ directive writing between 1 and 11 bytes 
into a region of size 10 [-Werror=format-overflow=]
argp-test.c:130:19: note: directive argument in the range [-2147483648, 122]
argp-test.c:130:5: note: ‘sprintf’ output between 2 and 12 bytes into a 
destination of size 10

-nss/tst-field.c:
tst-field.c:52:7: error: ‘%s’ directive argument is null 
[-Werror=format-overflow=]

Bye
Stefan

ChangeLog:

	* string/test-strcasestr.c (check_result): Add NULL check.
	* nss/tst-field.c (check_rewrite): Likewise.
	* argp/argp-test.c (popt): Increase size of buf to 12.

Comments

Yann Droneaud June 17, 2019, 8:54 a.m. | #1
Hi,

Le lundi 17 juin 2019 à 08:35 +0200, Stefan Liebler a écrit :
> 

> this patch fixes the following gcc 9 warnings for "make xcheck":

> -string/tst-strcasestr.c:

> ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive 

> argument is null [-Werror=format-overflow=]

> 


This was reported as bug #24556

https://sourceware.org/bugzilla/show_bug.cgi?id=24556

Regards.

-- 
Yann Droneaud
OPTEYA
Stefan Liebler June 17, 2019, 1:55 p.m. | #2
On 6/17/19 10:54 AM, Yann Droneaud wrote:
> Hi,

> 

> Le lundi 17 juin 2019 à 08:35 +0200, Stefan Liebler a écrit :

>>

>> this patch fixes the following gcc 9 warnings for "make xcheck":

>> -string/tst-strcasestr.c:

>> ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive

>> argument is null [-Werror=format-overflow=]

>>

> 

> This was reported as bug #24556

> 

> https://sourceware.org/bugzilla/show_bug.cgi?id=24556

> 

> Regards.

> 


Thanks for this hint.
I've updated the patch and I'm now able to run "make xcheck" and "make 
bench" with gcc 9.

Bye
Stefan
commit e70b20854924ea42aeb27579a07d8019f6bffb64
Author: Stefan Liebler <stli@linux.ibm.com>
Date:   Fri Jun 14 12:54:38 2019 +0200

    Fix gcc 9 build errors for make xcheck. [BZ #24556]
    
    This patch fixes the following gcc 9 warnings for "make xcheck" / "make bench":
    -string/tst-strcasestr.c:
    ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    -argp/argp-test.c:
    argp-test.c:130:20: error: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Werror=format-overflow=]
    argp-test.c:130:19: note: directive argument in the range [-2147483648, 122]
    argp-test.c:130:5: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
    
    -nss/tst-field.c:
    tst-field.c:52:7: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
     Please enter the commit message for your changes. Lines starting
    
    -benchtests/bench-strstr.c:
    ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    -benchtests/bench-malloc-simple.c:
    bench-malloc-simple.c:93:16: error: iteration 3 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
    
    ChangeLog:
    
            [BZ #24556]
            * string/test-strcasestr.c (check_result): Add NULL check.
            * nss/tst-field.c (check_rewrite): Likewise.
            * benchtests/bench-strstr.c (do_one_test): Likewise.
            * argp/argp-test.c (popt): Increase size of buf to 12.
            * benchtests/bench-malloc-simple.c (bench):
            Do not initialize tests array out of bounds.

diff --git a/argp/argp-test.c b/argp/argp-test.c
index cb2976ddad..13e0c6df14 100644
--- a/argp/argp-test.c
+++ b/argp/argp-test.c
@@ -123,7 +123,7 @@ static const char doc[] = "Test program for argp."
 static void
 popt (int key, char *arg)
 {
-  char buf[10];
+  char buf[12];
   if (isprint (key))
     sprintf (buf, "%c", key);
   else
diff --git a/benchtests/bench-malloc-simple.c b/benchtests/bench-malloc-simple.c
index b8bb2cc116..c4f06f6999 100644
--- a/benchtests/bench-malloc-simple.c
+++ b/benchtests/bench-malloc-simple.c
@@ -87,7 +87,7 @@ bench (unsigned long size)
   size_t iters = NUM_ITERS;
   int **arr = (int**) malloc (MAX_ALLOCS * sizeof (void*));
 
-  for (int t = 0; t <= 3; t++)
+  for (int t = 0; t < 3; t++)
     for (int i = 0; i < NUM_ALLOCS; i++)
       {
 	tests[t][i].n = allocs[i];
diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c
index 2cbe13e9ac..14053e7a22 100644
--- a/benchtests/bench-strstr.c
+++ b/benchtests/bench-strstr.c
@@ -147,7 +147,7 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
   if (res != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     res, exp_result);
+	     res, (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
     }
 }
diff --git a/nss/tst-field.c b/nss/tst-field.c
index 23d2f2abf6..5c553e5f46 100644
--- a/nss/tst-field.c
+++ b/nss/tst-field.c
@@ -50,7 +50,7 @@ check_rewrite (const char *input, const char *expected)
   if (result != NULL && strcmp (result, expected) != 0)
     {
       printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
-	      input, result, expected);
+	      (input == NULL) ? "NULL" : input, result, expected);
       errors = true;
     }
   free (to_free);
diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c
index 0a16f85dcd..1773581a3e 100644
--- a/string/test-strcasestr.c
+++ b/string/test-strcasestr.c
@@ -67,7 +67,7 @@ check_result (impl_t *impl, const char *s1, const char *s2,
   if (result != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     result, exp_result);
+	     result, (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
       return -1;
     }
Andreas Schwab June 17, 2019, 2:07 p.m. | #3
On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

> diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c

> index 2cbe13e9ac..14053e7a22 100644

> --- a/benchtests/bench-strstr.c

> +++ b/benchtests/bench-strstr.c

> @@ -147,7 +147,7 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)

>    if (res != exp_result)

>      {

>        error (0, 0, "Wrong result in function %s %s %s", impl->name,

> -	     res, exp_result);

> +	     res, (exp_result == NULL) ? "NULL" : exp_result);


res can be NULL too.

> diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c

> index 0a16f85dcd..1773581a3e 100644

> --- a/string/test-strcasestr.c

> +++ b/string/test-strcasestr.c

> @@ -67,7 +67,7 @@ check_result (impl_t *impl, const char *s1, const char *s2,

>    if (result != exp_result)

>      {

>        error (0, 0, "Wrong result in function %s %s %s", impl->name,

> -	     result, exp_result);

> +	     result, (exp_result == NULL) ? "NULL" : exp_result);


result can be NULL too.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Stefan Liebler June 17, 2019, 2:22 p.m. | #4
On 6/17/19 4:07 PM, Andreas Schwab wrote:
> On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

> 

>> diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c

>> index 2cbe13e9ac..14053e7a22 100644

>> --- a/benchtests/bench-strstr.c

>> +++ b/benchtests/bench-strstr.c

>> @@ -147,7 +147,7 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)

>>     if (res != exp_result)

>>       {

>>         error (0, 0, "Wrong result in function %s %s %s", impl->name,

>> -	     res, exp_result);

>> +	     res, (exp_result == NULL) ? "NULL" : exp_result);

> 

> res can be NULL too.

> 

>> diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c

>> index 0a16f85dcd..1773581a3e 100644

>> --- a/string/test-strcasestr.c

>> +++ b/string/test-strcasestr.c

>> @@ -67,7 +67,7 @@ check_result (impl_t *impl, const char *s1, const char *s2,

>>     if (result != exp_result)

>>       {

>>         error (0, 0, "Wrong result in function %s %s %s", impl->name,

>> -	     result, exp_result);

>> +	     result, (exp_result == NULL) ? "NULL" : exp_result);

> 

> result can be NULL too.

> 

> Andreas.

> 


That's true.
The compiler does not emit a warning for those.
Shall we nevertheless add a check?

Bye
Stefan
Andreas Schwab June 17, 2019, 2:59 p.m. | #5
On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

> On 6/17/19 4:07 PM, Andreas Schwab wrote:

>> On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

>>

>>> diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c

>>> index 2cbe13e9ac..14053e7a22 100644

>>> --- a/benchtests/bench-strstr.c

>>> +++ b/benchtests/bench-strstr.c

>>> @@ -147,7 +147,7 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)

>>>     if (res != exp_result)

>>>       {

>>>         error (0, 0, "Wrong result in function %s %s %s", impl->name,

>>> -	     res, exp_result);

>>> +	     res, (exp_result == NULL) ? "NULL" : exp_result);

>>

>> res can be NULL too.

>>

>>> diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c

>>> index 0a16f85dcd..1773581a3e 100644

>>> --- a/string/test-strcasestr.c

>>> +++ b/string/test-strcasestr.c

>>> @@ -67,7 +67,7 @@ check_result (impl_t *impl, const char *s1, const char *s2,

>>>     if (result != exp_result)

>>>       {

>>>         error (0, 0, "Wrong result in function %s %s %s", impl->name,

>>> -	     result, exp_result);

>>> +	     result, (exp_result == NULL) ? "NULL" : exp_result);

>>

>> result can be NULL too.

>>

>> Andreas.

>>

>

> That's true.

> The compiler does not emit a warning for those.

> Shall we nevertheless add a check?


Either check both or none.  If NULL is a problem then it needs to be
checked everywhere.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Stefan Liebler June 17, 2019, 4:02 p.m. | #6
On 6/17/19 4:59 PM, Andreas Schwab wrote:
> On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

> 

>> On 6/17/19 4:07 PM, Andreas Schwab wrote:

>>> On Jun 17 2019, Stefan Liebler <stli@linux.ibm.com> wrote:

>>>

>>>> diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c

>>>> index 2cbe13e9ac..14053e7a22 100644

>>>> --- a/benchtests/bench-strstr.c

>>>> +++ b/benchtests/bench-strstr.c

>>>> @@ -147,7 +147,7 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)

>>>>      if (res != exp_result)

>>>>        {

>>>>          error (0, 0, "Wrong result in function %s %s %s", impl->name,

>>>> -	     res, exp_result);

>>>> +	     res, (exp_result == NULL) ? "NULL" : exp_result);

>>>

>>> res can be NULL too.

>>>

>>>> diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c

>>>> index 0a16f85dcd..1773581a3e 100644

>>>> --- a/string/test-strcasestr.c

>>>> +++ b/string/test-strcasestr.c

>>>> @@ -67,7 +67,7 @@ check_result (impl_t *impl, const char *s1, const char *s2,

>>>>      if (result != exp_result)

>>>>        {

>>>>          error (0, 0, "Wrong result in function %s %s %s", impl->name,

>>>> -	     result, exp_result);

>>>> +	     result, (exp_result == NULL) ? "NULL" : exp_result);

>>>

>>> result can be NULL too.

>>>

>>> Andreas.

>>>

>>

>> That's true.

>> The compiler does not emit a warning for those.

>> Shall we nevertheless add a check?

> 

> Either check both or none.  If NULL is a problem then it needs to be

> checked everywhere.

> 

> Andreas.

> 

Okay I've added the two mentioned occurrences and also added checks in 
string/test-strstr.c.

Bye
Stefan
commit 22e4ba39c88bcb2c75e8f038551cd75362c17298
Author: Stefan Liebler <stli@linux.ibm.com>
Date:   Fri Jun 14 12:54:38 2019 +0200

    Fix gcc 9 build errors for make xcheck. [BZ #24556]
    
    This patch fixes the following gcc 9 warnings for "make xcheck" / "make bench":
    -string/tst-strcasestr.c:
    ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    -argp/argp-test.c:
    argp-test.c:130:20: error: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Werror=format-overflow=]
    argp-test.c:130:19: note: directive argument in the range [-2147483648, 122]
    argp-test.c:130:5: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
    
    -nss/tst-field.c:
    tst-field.c:52:7: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
     Please enter the commit message for your changes. Lines starting
    
    -benchtests/bench-strstr.c:
    ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    -benchtests/bench-malloc-simple.c:
    bench-malloc-simple.c:93:16: error: iteration 3 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
    
    ChangeLog:
    
            [BZ #24556]
            * string/test-strcasestr.c (check_result): Add NULL check.
            * nss/tst-field.c (check_rewrite): Likewise.
            * benchtests/bench-strstr.c (do_one_test): Likewise.
            * string/test-strstr.c (check_result): Likewise.
            * argp/argp-test.c (popt): Increase size of buf to 12.
            * benchtests/bench-malloc-simple.c (bench):
            Do not initialize tests array out of bounds.
    
    meld

diff --git a/argp/argp-test.c b/argp/argp-test.c
index cb2976ddad..13e0c6df14 100644
--- a/argp/argp-test.c
+++ b/argp/argp-test.c
@@ -123,7 +123,7 @@ static const char doc[] = "Test program for argp."
 static void
 popt (int key, char *arg)
 {
-  char buf[10];
+  char buf[12];
   if (isprint (key))
     sprintf (buf, "%c", key);
   else
diff --git a/benchtests/bench-malloc-simple.c b/benchtests/bench-malloc-simple.c
index b8bb2cc116..c4f06f6999 100644
--- a/benchtests/bench-malloc-simple.c
+++ b/benchtests/bench-malloc-simple.c
@@ -87,7 +87,7 @@ bench (unsigned long size)
   size_t iters = NUM_ITERS;
   int **arr = (int**) malloc (MAX_ALLOCS * sizeof (void*));
 
-  for (int t = 0; t <= 3; t++)
+  for (int t = 0; t < 3; t++)
     for (int i = 0; i < NUM_ALLOCS; i++)
       {
 	tests[t][i].n = allocs[i];
diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c
index 2cbe13e9ac..c1cdcdd5bb 100644
--- a/benchtests/bench-strstr.c
+++ b/benchtests/bench-strstr.c
@@ -147,7 +147,8 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
   if (res != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     res, exp_result);
+	     (res == NULL) ? "NULL" : res,
+	     (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
     }
 }
diff --git a/nss/tst-field.c b/nss/tst-field.c
index 23d2f2abf6..5c553e5f46 100644
--- a/nss/tst-field.c
+++ b/nss/tst-field.c
@@ -50,7 +50,7 @@ check_rewrite (const char *input, const char *expected)
   if (result != NULL && strcmp (result, expected) != 0)
     {
       printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
-	      input, result, expected);
+	      (input == NULL) ? "NULL" : input, result, expected);
       errors = true;
     }
   free (to_free);
diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c
index 0a16f85dcd..f7cbcc14ef 100644
--- a/string/test-strcasestr.c
+++ b/string/test-strcasestr.c
@@ -67,7 +67,8 @@ check_result (impl_t *impl, const char *s1, const char *s2,
   if (result != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     result, exp_result);
+	     (result == NULL) ? "NULL" : result,
+	     (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
       return -1;
     }
diff --git a/string/test-strstr.c b/string/test-strstr.c
index 031aff5534..17d505a228 100644
--- a/string/test-strstr.c
+++ b/string/test-strstr.c
@@ -66,7 +66,8 @@ check_result (impl_t *impl, const char *s1, const char *s2,
   if (result != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     result, exp_result);
+	     (result == NULL) ? "NULL" : result,
+	     (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
       return -1;
     }

Patch

commit 4b7c870e47625e91f89258bd8e3cd3ca51787556
Author: Stefan Liebler <stli@linux.ibm.com>
Date:   Fri Jun 14 12:47:39 2019 +0200

    Fix gcc 9 build errors for make xcheck.
    
    This patch fixes the following gcc 9 warnings for "make xcheck":
    -string/tst-strcasestr.c:
    ../include/bits/../../misc/bits/error.h:42:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    -argp/argp-test.c:
    argp-test.c:130:20: error: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Werror=format-overflow=]
    argp-test.c:130:19: note: directive argument in the range [-2147483648, 122]
    argp-test.c:130:5: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
    
    -nss/tst-field.c:
    tst-field.c:52:7: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    
    ChangeLog:
    
            * string/test-strcasestr.c (check_result): Add NULL check.
            * nss/tst-field.c (check_rewrite): Likewise.
            * argp/argp-test.c (popt): Increase size of buf to 12.

diff --git a/argp/argp-test.c b/argp/argp-test.c
index cb2976ddad..13e0c6df14 100644
--- a/argp/argp-test.c
+++ b/argp/argp-test.c
@@ -123,7 +123,7 @@  static const char doc[] = "Test program for argp."
 static void
 popt (int key, char *arg)
 {
-  char buf[10];
+  char buf[12];
   if (isprint (key))
     sprintf (buf, "%c", key);
   else
diff --git a/nss/tst-field.c b/nss/tst-field.c
index 23d2f2abf6..5c553e5f46 100644
--- a/nss/tst-field.c
+++ b/nss/tst-field.c
@@ -50,7 +50,7 @@  check_rewrite (const char *input, const char *expected)
   if (result != NULL && strcmp (result, expected) != 0)
     {
       printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
-	      input, result, expected);
+	      (input == NULL) ? "NULL" : input, result, expected);
       errors = true;
     }
   free (to_free);
diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c
index 0a16f85dcd..1773581a3e 100644
--- a/string/test-strcasestr.c
+++ b/string/test-strcasestr.c
@@ -67,7 +67,7 @@  check_result (impl_t *impl, const char *s1, const char *s2,
   if (result != exp_result)
     {
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
-	     result, exp_result);
+	     result, (exp_result == NULL) ? "NULL" : exp_result);
       ret = 1;
       return -1;
     }