From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48159 invoked by alias); 7 Sep 2017 16:20:21 -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 48140 invoked by uid 89); 7 Sep 2017 16:20:20 -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-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-oi0-f45.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=q/bvPl2vK2f1izhnZuriC0vMOGVzp9OP/vL5Fww+Odo=; b=Xnn3JFCdUunmVG0irJ/h2GyGWnMEczAwlFOohmkmPfEb+Ugii/8bQ+zmEZd4qPztT7 T9xeYbudHC7uMuL/fJxVHUeiJtaRO7Hr+eA9pnBKffFzl2/d0KklXBy4jPt39RbtuvWU K+aj668fHT3P3v1dsK3QuajBS0XxG0VQy7ceo0JBmXfxcv1CsHnyyGQFMT6y1KACLIxV 7UDZUIRAUHA8wm4efRkMkGQt4n+ePF8mgGM/y6LrZ1f5da1kEg+1qFebvx87zy6so8us gsQ9gTT3yiVAQYdKDYjU2hpkW0zD2RN/eYl/DK93+L8MBLJGsHDdn8R8pNd08VwHdY4V JfXg== X-Gm-Message-State: AHPjjUjIH+O099jcTKLAcaUC+S/RIyy2YwlI5po16abO9vLbYFE6ri3y X/jj/h9ae+8br0HakOJteZUDsdqqEg== X-Google-Smtp-Source: ADKCNb7o4KkxCRyKlXXLNpp6JT3oSQ+wz47YCuiAdCz72F+vGOlbNb7ZVadWsWoOPgphNvGNr6F0KmbWV8Mz6fFnuIo= X-Received: by 10.202.4.6 with SMTP id 6mr3146748oie.240.1504801213653; Thu, 07 Sep 2017 09:20:13 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: 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: Thu, 07 Sep 2017 16:20:00 -0000 Message-ID: Subject: Re: [PATCH] string/stratcliff.c: Replace int with size_t [BZ #21982] To: Stefan Liebler , Libc-stable Mailing List Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2017-09/txt/msg00302.txt.bz2 On Wed, Aug 23, 2017 at 7:49 AM, H.J. Lu wrote: > On Tue, Aug 22, 2017 at 7:56 AM, Stefan Liebler = wrote: >> 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); --out= er) >>>>>>>> >>>>>>>> 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 infin= ite >>>>>>>> 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 repla= ce >>>>>>>> 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 n= ot >> occur anymore. > > I am checking it in shortly. > I'd like to backport it to 2.25 and 2.26 branches. Any comments? --=20 H.J.