From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id E2BC73858C83 for ; Sat, 22 Apr 2023 07:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2BC73858C83 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1682148768; bh=NrwOM1B4DZA3PsPz/7rw76zrattjT0LJT6NHLUTyZqc=; h=Subject:From:To:Date:In-Reply-To:References:From; b=hiXujIV6JDTQOsnzP13L/GfqnUXeD2/5uK2ZKQY43zyBt0fUQZXScAorKqrlAeB4b Nd+anN7pk2rgeJL0TA0kPOEvCrXa7Px1JiFS72Fw215YmVqchM+3kxvipLp38nbKph 1jYAz8a/Hq6UNK+g6BKpspHPaCpAtpCduLyxDnac= Received: from [IPv6:240e:358:1142:c600:dc73:854d:832e:2] (unknown [IPv6:240e:358:1142:c600:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 954D465B42; Sat, 22 Apr 2023 03:32:43 -0400 (EDT) Message-ID: <211642b165735b9271aa505bc11bf0430b0205d0.camel@xry111.site> Subject: Re: [PATCH] libio: Add __nonnull for FILE * arguments of fclose and freopen From: Xi Ruoyao To: Adhemerval Zanella Netto , libc-alpha@sourceware.org Date: Sat, 22 Apr 2023 15:32:37 +0800 In-Reply-To: <6486b199-adec-57c7-4a08-4a98fd57ab0d@linaro.org> References: <20230421062133.2084910-1-xry111@xry111.site> <6486b199-adec-57c7-4a08-4a98fd57ab0d@linaro.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.0 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,SPF_HELO_PASS,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: On Fri, 2023-04-21 at 10:00 -0300, Adhemerval Zanella Netto wrote: >=20 >=20 > On 21/04/23 03:21, Xi Ruoyao wrote: > > Calling fclose or freopen with a null FILE * is undefined behavior, > > and > > doing so in practice will cause a SIGSEGV.=C2=A0 So it seems suitable f= or > > __nonnull. > >=20 > > This will help the compiler to warn for some buggy code, like > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109570. >=20 > LGTM, thanks. Thanks, please commit it if there is no objections. Or may I get a write after approve access for glibc.git? >=20 > Reviewed-by: Adhemerval Zanella=C2=A0 >=20 > > --- > > =C2=A0libio/stdio.h | 6 +++--- > > =C2=A01 file changed, 3 insertions(+), 3 deletions(-) > >=20 > > diff --git a/libio/stdio.h b/libio/stdio.h > > index 45ddafdf20..bfb8415d3b 100644 > > --- a/libio/stdio.h > > +++ b/libio/stdio.h > > @@ -180,7 +180,7 @@ extern int renameat2 (int __oldfd, const char > > *__old, int __newfd, > > =C2=A0 > > =C2=A0=C2=A0=C2=A0 This function is a possible cancellation point and t= herefore not > > =C2=A0=C2=A0=C2=A0 marked with __THROW.=C2=A0 */ > > -extern int fclose (FILE *__stream); > > +extern int fclose (FILE *__stream) __nonnull ((1)); > > =C2=A0 > > =C2=A0#undef __attr_dealloc_fclose > > =C2=A0#define __attr_dealloc_fclose __attr_dealloc (fclose, 1) > > @@ -269,7 +269,7 @@ extern FILE *fopen (const char *__restrict > > __filename, > > =C2=A0=C2=A0=C2=A0 marked with __THROW.=C2=A0 */ > > =C2=A0extern FILE *freopen (const char *__restrict __filename, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *__res= trict __modes, > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 FILE *__restrict __stre= am) __wur; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 FILE *__restrict __stre= am) __wur __nonnull > > ((3)); > > =C2=A0#else > > =C2=A0# ifdef __REDIRECT > > =C2=A0extern FILE *__REDIRECT (fopen, (const char *__restrict __filenam= e, > > @@ -290,7 +290,7 @@ extern FILE *fopen64 (const char *__restrict > > __filename, > > =C2=A0=C2=A0 __attribute_malloc__ __attr_dealloc_fclose __wur; > > =C2=A0extern FILE *freopen64 (const char *__restrict __filename, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= const char *__restrict __modes, > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0FILE *= __restrict __stream) __wur; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0FILE *= __restrict __stream) __wur __nonnull > > ((3)); > > =C2=A0#endif > > =C2=A0 > > =C2=A0#ifdef=C2=A0__USE_POSIX --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University