From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96081 invoked by alias); 21 Aug 2017 14:53:25 -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 96071 invoked by uid 89); 21 Aug 2017 14:53:24 -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-f68.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=zQlL5GddWJHj+xS+9d17uOHe3tmcYPeSdVavK4LbICw=; b=NHncFCcdM3EzAA2pXTnMAXnsmTRenJSlMDvw24BVe1smaLqNFVESB2qWn+YMOzmanE UXALOv0ozNh/hnMFMCs0DJqDQIWLXGLPHjYMdT53RVcJxvnSRGq7uY35V3qD+ssJgYEH E17eZSTbvEKbJsI96Vp0/tV/dtYhpFhMylvoRq7Pyk/vcQ4gp6lCWzbTBCQ+YLJVkde9 DSdT+B9DyryTdSdFBINKLrPtLaIh246uCAqJd6vseL+QYXXvLEDVRTTjR6Obiouxen5C Ox3JpUk91LCoJ0xJhiQ+vWHDRCNZB2Qmi+1bfMgcAolcuFO54y8WbZY9HWsukOoZyixs 4yWQ== X-Gm-Message-State: AHYfb5iJSA92P/hiB+LYozZ5m4Ba+YMbE8JwqZdUpNOBNzV5hQvXXvnK KnV8wV9vA5Co5xFw3qOBfmD8ue/8T7gt X-Received: by 10.202.227.5 with SMTP id a5mr21430662oih.240.1503327201234; Mon, 21 Aug 2017 07:53:21 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <25604b34-7afb-7007-4ea8-3add9963d4b4@linux.vnet.ibm.com> References: <20170820171713.GA19531@gmail.com> <25604b34-7afb-7007-4ea8-3add9963d4b4@linux.vnet.ibm.com> From: "H.J. Lu" Date: Mon, 21 Aug 2017 14:53: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/msg00992.txt.bz2 On Mon, Aug 21, 2017 at 6:48 AM, Stefan Liebler w= rote: > 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); --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 >=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. --=20 H.J.