public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Liebler <stli@linux.vnet.ibm.com>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH] string/stratcliff.c: Replace int with size_t [BZ #21982]
Date: Mon, 21 Aug 2017 13:49:00 -0000	[thread overview]
Message-ID: <25604b34-7afb-7007-4ea8-3add9963d4b4@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170820171713.GA19531@gmail.com>

On 08/20/2017 07:17 PM, H.J. Lu wrote:
> Fix GCC 7 errors when string/stratcliff.c is compiled with -O3:
> 
> stratcliff.c: In function ‘do_test’:
> cc1: error: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Werror=strict-overflow]
> 
> OK for master?
> 
> H.J.
> ---
> 	[BZ #21982]
> 	* string/stratcliff.c (do_test): Declare size, nchars, inner,
> 	middle and outer with size_t instead of int.  Repleace %d with
> 	%Zd in printf.
> ---
>   string/stratcliff.c | 72 ++++++++++++++++++++++++++---------------------------
>   1 file changed, 36 insertions(+), 36 deletions(-)
> 
> diff --git a/string/stratcliff.c b/string/stratcliff.c
> index e28b0c5058..ae780379cb 100644
> --- a/string/stratcliff.c
> +++ b/string/stratcliff.c
> @@ -58,8 +58,8 @@
>   int
>   do_test (void)
>   {
> -  int size = sysconf (_SC_PAGESIZE);
> -  int nchars = size / sizeof (CHAR);
> +  size_t size = sysconf (_SC_PAGESIZE);
> +  size_t nchars = size / sizeof (CHAR);
>     CHAR *adr;
>     CHAR *dest;
>     int result = 0;
> @@ -80,7 +80,7 @@ do_test (void)
>       }
>     else
>       {
> -      int inner, middle, outer;
> +      size_t inner, middle, outer;
> 
>         mprotect (adr, size, PROT_NONE);
>         mprotect (adr + 2 * nchars, size, PROT_NONE);
> @@ -101,7 +101,7 @@ do_test (void)
> 
>   	      if (STRLEN (&adr[outer]) != (size_t) (inner - outer))
>   		{
> -		  printf ("%s flunked for outer = %d, inner = %d\n",
> +		  printf ("%s flunked for outer = %Zd, inner = %Zd\n",
>   			  STRINGIFY (STRLEN), outer, inner);
>   		  result = 1;
>   		}
>   		{
> -		  printf ("%s flunked for outer = %d, middle = %d\n",
> +		  printf ("%s flunked for outer = %Zd, middle = %Zd\n",
>   			  STRINGIFY (rawmemchr), outer, middle);
>   		  result = 1;
>   		}
> Hi H.J. Lu,

I've applied your patch and the warnings does not occur anymore on s390.

The outer loops of the string tests are all using the following:
size_t nchars, outer;
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)

I think we can assume, that nchars is always > 128 as it is derived by 
the pagesize.
But if nchars would be equal to 128, this would result in an infinite 
loop (outer >= 0)?
If nchars would be less than 128, the tests would be skipped.

Should we add a check that nchars > 128 at the beginning and replace the 
"MAX (0, nchars - 128)" with only "nchars - 128"?

Bye,
Stefan

  parent reply	other threads:[~2017-08-21 13:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-20 17:17 H.J. Lu
2017-08-21 13:25 ` Joseph Myers
2017-08-21 13:51   ` H.J. Lu
2017-08-21 13:56     ` Joseph Myers
2017-08-21 15:03       ` H.J. Lu
2017-08-21 13:49 ` Stefan Liebler [this message]
2017-08-21 14:53   ` H.J. Lu
2017-08-21 15:41     ` Stefan Liebler
2017-08-21 23:05       ` H.J. Lu
2017-08-22 12:07         ` Stefan Liebler
2017-08-22 12:43           ` H.J. Lu
2017-08-22 14:57             ` Stefan Liebler
2017-08-23 14:49               ` H.J. Lu
2017-09-07 16:20                 ` H.J. Lu
2017-09-11 15:46                   ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25604b34-7afb-7007-4ea8-3add9963d4b4@linux.vnet.ibm.com \
    --to=stli@linux.vnet.ibm.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).