From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112916 invoked by alias); 11 Sep 2017 15:46:06 -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 112293 invoked by uid 89); 11 Sep 2017 15:46:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=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-io0-f173.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=vl/9eTtUdM9bKnDbPf1hX77JnkpkRSZBQsXOiQk9+W4=; b=muufgDIfhCLm+E40ujokn0SjwICzj1N6qqdrRVPHctQ+HDxaplFY7Z2lASR9PUO9fo zaiOa5+sTi2v+SL4Ik73zlG87wtmxeFTxO643l5jg9UVV+/dCKNvjaNzYn2YxhaoMequ EupmaeqdFC+0a2xDVvBpOvISQk+sp4PzIw3Mc2DcGnVJYqfyP+Xxzok0c3/GzFi58E85 TCFFZXcRKAFebJBeLxxDyLfOCQaq9mh9wlzEctmKPd8MEVbJ+/6bi4t1mgHL9zMvZldv C02Xw/rg1t+516y8Vo44iXsT5EZoLWH09mIR4X4KHLxX+t0MGFDm7JxQmFfKxtZo5SMb nmLQ== X-Gm-Message-State: AHPjjUgp5RB+9YwiojqGQEc+ZondYZU6sUpffPewQqIiSWpeoFD4y5+V HpLSymOGUEDpixvGF38yfi/o5gD7oA== X-Google-Smtp-Source: AOwi7QBBFAvfMqtwqbvxqKgWEEBwcPQEypzn8vmHx2PlsMzWwH6PY+HYiFRTBasdQhseEDtAjYCuRoqgdK0PwfgHTE8= X-Received: by 10.202.102.25 with SMTP id a25mr10579269oic.301.1505144762202; Mon, 11 Sep 2017 08:46:02 -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: Mon, 11 Sep 2017 15:46: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/msg00449.txt.bz2 On Thu, Sep 7, 2017 at 9:20 AM, H.J. Lu wrote: > 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. Repleac= e %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, middl= e); >>>>>>>>>> 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); --ou= ter) >>>>>>>>> >>>>>>>>> I think we can assume, that nchars is always > 128 as it is deriv= ed >>>>>>>>> by >>>>>>>>> the >>>>>>>>> pagesize. >>>>>>>>> But if nchars would be equal to 128, this would result in an infi= nite >>>>>>>>> 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 repl= ace >>>>>>>>> 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 loo= p 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. >> > > I'd like to backport it to 2.25 and 2.26 branches. Any comments? > I am checking it in now. --=20 H.J.