From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 7E00E3857B9B for ; Thu, 8 Jun 2023 05:50:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E00E3857B9B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-510f866ce78so35785a12.1 for ; Wed, 07 Jun 2023 22:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686203455; x=1688795455; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=44573UkdAtk09y/8K1AwVtSnULkv77SExSa0/NMmrS4=; b=QtJDxB/yfymf6rWY9XFAQC75oDmCrEd3fT/JIC6LTnZrBxmsjMO2jWThcT8dpLnmue aiPUwfo1ZoG7vZSv5+dnTgVWRKJVXaFiK48jbY8fHgozKZ7uYngjoi0KRHfqrE+XaYdL y5WEwdk+rDtPlz+hHb1uiwQ0LRM3CcnEfeyRtaV0Y8hqbcPWtLvPutIDmW2glomOReMF hKx64iWN6b4lIs+HlLsJH21ZMZ7n912fpAesFAG0FgJFfL7hRldPz5eug76W+lthJ+it l7ovhCo+5/rKAnT45oh4rjwhWri9GaD1Z7Io2S/0QzUIVGmnn4KypVpcJqY+dPPcb4b2 Cl8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686203455; x=1688795455; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=44573UkdAtk09y/8K1AwVtSnULkv77SExSa0/NMmrS4=; b=VPxtvPmOqF7jkgqTaxZZVwYZ70Ycd4Rvqyze4vNK/KY77S2xbhz00vF/SEObE5BuH9 QpEWUFpqSREGAlgn/jQL0qj/6nUnbuIJCE4JiDuNv+pdp1leZmmY42DBbEP8Qkr7dHkA sAxBpoREGQQnmowB5p6hQ95KhUidLmXYLJMQhzt6MOIdJwkIGp39z/35sXHtlEj+Mt4p wUIYqv2tZaqmA+PG3xiQRlYXwGaxhfmQ8FynhBSDNciT8hPJhl0zqiagu2mJ2xTZoD78 tCg3TgRTdIeUjpwBybryGOv615jn+yOcswg3OGfYj/FTf1sGXi0xeAR+lEova8lE27c8 mJPg== X-Gm-Message-State: AC+VfDzXASyVsuVvFIzQnykEIql3utTu4Gt95AITEgorYLWd87RFHjkR gP+aNBs6cwpHoE30fwMCeuffANbCnCa9w6BnQg== X-Google-Smtp-Source: ACHHUZ4mt2GCTGJEhR1DX4VH97SFlVzQo3Gx34uElzX7YlOb77DoR9+F20Ho/8lbeShcIXybnYG69A== X-Received: by 2002:a05:6402:524e:b0:50c:79f:c693 with SMTP id t14-20020a056402524e00b0050c079fc693mr2200853edd.1.1686203455089; Wed, 07 Jun 2023 22:50:55 -0700 (PDT) Received: from smtpclient.apple ([2a00:cc47:21fb:f100:5c7:9e40:49bd:38e7]) by smtp.gmail.com with ESMTPSA id kk20-20020a170907767400b00967004187b8sm231749ejc.36.2023.06.07.22.50.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2023 22:50:54 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Subject: Re: [PATCH v6 5/7] tests: replace fgets by xfgets From: Maxim Kuvyrkov In-Reply-To: <20230602152812.108497-6-fberat@redhat.com> Date: Thu, 8 Jun 2023 09:50:42 +0400 Cc: Maxim Kuvyrkov via Libc-alpha , siddhesh@gotplt.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20230602152812.108497-1-fberat@redhat.com> <20230602152812.108497-6-fberat@redhat.com> To: =?utf-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= X-Mailer: Apple Mail (2.3731.500.231) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Fr=C3=A9d=C3=A9ric, One of the patches in this series fails lint-makefile test [1]. Let me = know if you need any assistance in reproducing this. =3D=3D=3D --- /home/maxim.kuvyrkov/tcwg_gnu/glibc/support/Makefile.expected +++ /home/maxim.kuvyrkov/tcwg_gnu/glibc/support/Makefile = 2023-06-08 05:41:24.238665318 +0000 @@ -126,8 +126,8 @@ xfgets \ xfopen \ xfork \ - xfread \ xfreopen \ + xfread \ xftruncate \ xgetline \ xgetsockname \ @@ -197,8 +197,8 @@ xpthread_spin_lock \ xpthread_spin_unlock \ xraise \ - xread \ xreadlink \ + xread \ xrealloc \ xrecvfrom \ xsendto \ @@ -211,8 +211,8 @@ xstrdup \ xstrndup \ xsymlink \ - xsysconf \ xsystem \ + xsysconf \ xunlink \ xuselocale \ xwaitpid \ --- Tested 200 Makefiles and 1 were incorrectly sorted Please use `patch -R -pN` and the output above to correct the sorting =3D=3D=3D [1] = https://ci.linaro.org/job/tcwg_glibc_check--master-aarch64-build/321/artif= act/artifacts/artifacts.precommit/07-check_regression/fails.sum/*view*/ -- Maxim Kuvyrkov https://www.linaro.org > On Jun 2, 2023, at 19:28, Fr=C3=A9d=C3=A9ric B=C3=A9rat via Libc-alpha = wrote: >=20 > With fortification enabled, fgets calls return result needs to be = checked, > has it gets the __wur macro enabled. > --- > Changes since v4/v5: > - Rebased >=20 > assert/test-assert-perr.c | 8 +++++--- > assert/test-assert.c | 8 +++++--- > stdio-common/test_rdwr.c | 11 ++++------- > support/Makefile | 1 + > support/xfgets.c | 32 ++++++++++++++++++++++++++++++++ > support/xstdio.h | 1 + > sysdeps/pthread/tst-cancel6.c | 3 ++- > 7 files changed, 50 insertions(+), 14 deletions(-) > create mode 100644 support/xfgets.c >=20 > diff --git a/assert/test-assert-perr.c b/assert/test-assert-perr.c > index 8496db6ffd..09a4fcb6ef 100644 > --- a/assert/test-assert-perr.c > +++ b/assert/test-assert-perr.c > @@ -11,6 +11,8 @@ > #include > #include >=20 > +#include > + > jmp_buf rec; > char buf[160]; >=20 > @@ -70,15 +72,15 @@ main(void) > failed =3D 1; /* should not happen */ >=20 > rewind (stderr); > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (!strstr(buf, strerror (1))) > failed =3D 1; >=20 > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, strerror (0))) > failed =3D 1; >=20 > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, strerror (2))) > failed =3D 1; >=20 > diff --git a/assert/test-assert.c b/assert/test-assert.c > index 26b58d4dd3..25e264543b 100644 > --- a/assert/test-assert.c > +++ b/assert/test-assert.c > @@ -11,6 +11,8 @@ > #include > #include >=20 > +#include > + > jmp_buf rec; > char buf[160]; >=20 > @@ -72,15 +74,15 @@ main (void) > failed =3D 1; /* should not happen */ >=20 > rewind (stderr); > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (!strstr (buf, "1 =3D=3D 2")) > failed =3D 1; >=20 > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, "1 =3D=3D 1")) > failed =3D 1; >=20 > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, "2 =3D=3D 3")) > failed =3D 1; >=20 > diff --git a/stdio-common/test_rdwr.c b/stdio-common/test_rdwr.c > index 7825ca9358..0544916eb1 100644 > --- a/stdio-common/test_rdwr.c > +++ b/stdio-common/test_rdwr.c > @@ -20,6 +20,7 @@ > #include > #include >=20 > +#include >=20 > int > main (int argc, char **argv) > @@ -49,7 +50,7 @@ main (int argc, char **argv) >=20 > (void) fputs (hello, f); > rewind (f); > - (void) fgets (buf, sizeof (buf), f); > + xfgets (buf, sizeof (buf), f); > rewind (f); > (void) fputs (buf, f); > rewind (f); > @@ -104,12 +105,8 @@ main (int argc, char **argv) > if (!lose) > { > rewind (f); > - if (fgets (buf, sizeof (buf), f) =3D=3D NULL) > - { > - printf ("fgets got %s.\n", strerror(errno)); > - lose =3D 1; > - } > - else if (strcmp (buf, replace)) > + xfgets (buf, sizeof (buf), f); > + if (strcmp (buf, replace)) > { > printf ("Read \"%s\" instead of \"%s\".\n", buf, replace); > lose =3D 1; > diff --git a/support/Makefile b/support/Makefile > index 3eed2deb1a..bbd3465d04 100644 > --- a/support/Makefile > +++ b/support/Makefile > @@ -123,6 +123,7 @@ libsupport-routines =3D \ > xdup2 \ > xfchmod \ > xfclose \ > + xfgets \ > xfopen \ > xfork \ > xfreopen \ > diff --git a/support/xfgets.c b/support/xfgets.c > new file mode 100644 > index 0000000000..e2db19cf53 > --- /dev/null > +++ b/support/xfgets.c > @@ -0,0 +1,32 @@ > +/* fgets with error checking. > + Copyright (C) 2016-2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be = useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > + > +#include > +#include > + > +char * > +xfgets (char *s, int size, FILE *stream) > +{ > + char *ret =3D fgets (s, size, stream); > + if (!ret && ferror(stream)) > + FAIL_EXIT1 ("fgets failed: %m"); > + > + return ret; > +} > diff --git a/support/xstdio.h b/support/xstdio.h > index 633c342c82..f30bee6a20 100644 > --- a/support/xstdio.h > +++ b/support/xstdio.h > @@ -28,6 +28,7 @@ FILE *xfopen (const char *path, const char *mode); > void xfclose (FILE *); > FILE *xfreopen (const char *path, const char *mode, FILE *stream); > void xfread (void *ptr, size_t size, size_t nmemb, FILE *stream); > +char *xfgets (char *s, int size, FILE *stream); >=20 > /* Read a line from FP, using getline. *BUFFER must be NULL, or a > heap-allocated pointer of *LENGTH bytes. Return the number of > diff --git a/sysdeps/pthread/tst-cancel6.c = b/sysdeps/pthread/tst-cancel6.c > index 63e6d49707..49b7399353 100644 > --- a/sysdeps/pthread/tst-cancel6.c > +++ b/sysdeps/pthread/tst-cancel6.c > @@ -20,12 +20,13 @@ > #include > #include >=20 > +#include >=20 > static void * > tf (void *arg) > { > char buf[100]; > - fgets (buf, sizeof (buf), arg); > + xfgets (buf, sizeof (buf), arg); > /* This call should never return. */ > return NULL; > } > --=20 > 2.40.1 >=20