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 E160A3858C20 for ; Tue, 16 May 2023 02:51:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E160A3858C20 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=1684205466; bh=uII0hDvwG0wdOoxju9jL3iFGldpbUX27NOuw6n901to=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OqKsHBYUrbe6b+4vjXv1+Dc8Niemac7OmHkOTwFz4riku/N7x7ah3b90xOpR7Rk1p rq6ZLhnpWX3FSntY8KBSTdypSAnBI1ykPWVzosbrodEBLzXHoY9O/blvzQBr4ZpDat h/sFYtnDwDvxod3WF3gZMjft3Lp7XjRnP69VwLC4= Received: from [IPv6:240e:358:114a:5700:dc73:854d:832e:5] (unknown [IPv6:240e:358:114a:5700:dc73:854d:832e:5]) (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 C824865A7C; Mon, 15 May 2023 22:51:02 -0400 (EDT) Message-ID: <08675b0b0b196802c08fc684c15c6a4bc09c7668.camel@xry111.site> Subject: Ping: [PATCH] libio: Add __nonnull for FILE * arguments of fclose and freopen From: Xi Ruoyao To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Netto , Carlos O'Donell Date: Tue, 16 May 2023 10:50:55 +0800 In-Reply-To: <20230421062133.2084910-1-xry111@xry111.site> References: <20230421062133.2084910-1-xry111@xry111.site> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.1 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: Ping, as this seems reviewed as OK but fallen through two review meetings.=20 On Fri, 2023-04-21 at 14:21 +0800, 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 for > __nonnull. >=20 > This will help the compiler to warn for some buggy code, like > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109570. > --- > =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 the= refore 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 *__restri= ct __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 __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 FILE *__restrict __stream)= __wur __nonnull > ((3)); > =C2=A0#else > =C2=A0# ifdef __REDIRECT > =C2=A0extern FILE *__REDIRECT (fopen, (const char *__restrict __filename, > @@ -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=A0con= st 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 *__r= estrict __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 *__r= estrict __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