From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44963 invoked by alias); 23 Aug 2017 14:49:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 44880 invoked by uid 89); 23 Aug 2017 14:49:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-oi0-f52.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=xvQtB9qj2tE/oPu8IYfrorESGVrV+FGFP+Sk6aHiwc8=; b=l36y0rkXmKSuD7SIGSDYssTHYSo8aSOc3fiPt54MiDHAnffKfboPLyWt4KZ7IQxC6J G+iwdMOT6CeQXM1dKMUF2/CpCyyPEpz7oKBcOWzZC7R+WUKqJPrfe4xHVCPpDT8gkkJL HrGaKA7OCCEyGdUPMZEd86TlWbYEUvO/S/4o8gKWCwQ2P/RXRWsx05wsr5Dc7SGrdWmm LkGrSbeya/m8ZCkuBo4bR5z4f7v8S/LK7ye5hAwg+2O/MkrR46VNMn3CALg4pQKLydmU Mp2kiuUqPep9tQxULKsxNWKC0XaK7IqF28ntf081GiHH48hOAWX86VbbXpYlum67BdNm 3HUQ== X-Gm-Message-State: AHYfb5jC35PY4yTi+LLNvZkB98LxzwSDVdNnt8ol80DBDR8t/G0p6umz QIsu/eFpvRl7VPkq3ADN97a7K3Uu+A== X-Received: by 10.202.179.85 with SMTP id c82mr3399480oif.5.1503499779298; Wed, 23 Aug 2017 07:49:39 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <3cf66cda-dcdf-1e56-d0d9-1f015d486692@linux.vnet.ibm.com> References: <20170820171713.GA19531@gmail.com> <25604b34-7afb-7007-4ea8-3add9963d4b4@linux.vnet.ibm.com> <10fd8eb0-0f53-9d4b-dcd2-694a1878c994@linux.vnet.ibm.com> <3cf66cda-dcdf-1e56-d0d9-1f015d486692@linux.vnet.ibm.com> From: "H.J. Lu" Date: Wed, 23 Aug 2017 14:49:00 -0000 Message-ID: Subject: Re: [PATCH] string/stratcliff.c: Replace int with size_t [BZ #21982] To: Stefan Liebler Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2017-08/txt/msg01118.txt.bz2 On Tue, Aug 22, 2017 at 7:56 AM, Stefan Liebler w= rote: > On 08/22/2017 02:43 PM, H.J. Lu wrote: >> >> On Tue, Aug 22, 2017 at 5:07 AM, Stefan Liebler >> wrote: >>> >>> On 08/22/2017 01:05 AM, H.J. Lu wrote: >>>> >>>> >>>> On Mon, Aug 21, 2017 at 8:41 AM, Stefan Liebler >>>> >>>> wrote: >>>>> >>>>> >>>>> On 08/21/2017 04:53 PM, H.J. Lu wrote: >>>>>> >>>>>> >>>>>> >>>>>> On Mon, Aug 21, 2017 at 6:48 AM, Stefan Liebler >>>>>> >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> 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 =E2=80=98do_test=E2=80=99: >>>>>>>> cc1: error: assuming signed overflow does not occur when assuming >>>>>>>> that >>>>>>>> (X >>>>>>>> - c) <=3D X is always true [-Werror=3Dstrict-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 =3D sysconf (_SC_PAGESIZE); >>>>>>>> - int nchars =3D size / sizeof (CHAR); >>>>>>>> + size_t size =3D sysconf (_SC_PAGESIZE); >>>>>>>> + size_t nchars =3D size / sizeof (CHAR); >>>>>>>> CHAR *adr; >>>>>>>> CHAR *dest; >>>>>>>> int result =3D 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]) !=3D (size_t) (inner - >>>>>>>> outer)) >>>>>>>> { >>>>>>>> - printf ("%s flunked for outer =3D %d, inner =3D = %d\n", >>>>>>>> + printf ("%s flunked for outer =3D %Zd, inner =3D >>>>>>>> %Zd\n", >>>>>>>> STRINGIFY (STRLEN), outer, inner); >>>>>>>> result =3D 1; >>>>>>>> } >>>>>>>> { >>>>>>>> - printf ("%s flunked for outer =3D %d, middle =3D >>>>>>>> %d\n", >>>>>>>> + printf ("%s flunked for outer =3D %Zd, middle =3D >>>>>>>> %Zd\n", >>>>>>>> STRINGIFY (rawmemchr), outer, middle); >>>>>>>> result =3D 1; >>>>>>>> } >>>>>>>> Hi H.J. Lu, >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> I've applied your patch and the warnings does not occur anymore on >>>>>>> s390. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Great. >>>>>> >>>>>>> The outer loops of the string tests are all using the following: >>>>>>> size_t nchars, outer; >>>>>>> for (outer =3D nchars - 1; outer >=3D MAX (0, nchars - 128); --oute= r) >>>>>>> >>>>>>> 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 infini= te >>>>>>> loop >>>>>>> (outer >=3D 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"? >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> This is a separate issue beyond BZ #21982. >>>>>> >>>>>> >>>>> Your patch is introducing this behaviour. >>>>> Before your patch, nchars and outer was an int and the >>>>> for-loop-condition >>>>> "outer >=3D MAX (0, nchars - 128)" does not lead to an infinite loop = or >>>>> to >>>>> skipping the test if nchars <=3D 128. >>>>> >>>> >>>> How about this patch? >>>> >>> This solves the cases if nchars < 128. >>> But if nchars =3D=3D 128, then the condition of the for-loop is "size_t= outer >>> >=3D >>> 0", which is always true. >>> >>> Could we check once if nchars > 128 and exit the test with an error if >>> nchars is <=3D 128? >>> Are there architectures where the page size is < 4096? >>> Or where wchar_t > 4byte? >>> >> >> Here is the updated patch. I added >> >> if (outer =3D=3D 0) >> break; >> >> at the end of loop. >> > > Okay. This fixes the case nchars =3D=3D 128. > I've retested this patch on s390x with gcc 7 -O3 and the warnings does not > occur anymore. I am checking it in shortly. Thanks. --=20 H.J.