From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 100EC3858D20 for ; Fri, 21 Apr 2023 06:21:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 100EC3858D20 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=1682058116; bh=81IXXGSRnSHMEB5/5Yhy7tK+WgakFg/JwMgQtxxZw/4=; h=From:To:Cc:Subject:Date:From; b=cNf4jh79a+upUILcCPbYi+XAeWHm6JN/6brvnSRiaSs39EBcqczPRPVGk8i7CiQf2 jMo2VWqSIJj0df5hneoxXFoD/XgMBvhGmU9js1X6Mbdu1a1YiniAeCnWgdaPEgWBp3 YpnqQLbJwEABB0DGZ3oqUK0xzR7Hai9xxgRVBQt4= Received: from stargazer.. (unknown [IPv6:240e:358:116f:3d00:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 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 7E71C66484; Fri, 21 Apr 2023 02:21:49 -0400 (EDT) From: Xi Ruoyao To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH] libio: Add __nonnull for FILE * arguments of fclose and freopen Date: Fri, 21 Apr 2023 14:21:33 +0800 Message-Id: <20230421062133.2084910-1-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,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: Calling fclose or freopen with a null FILE * is undefined behavior, and doing so in practice will cause a SIGSEGV. So it seems suitable for __nonnull. This will help the compiler to warn for some buggy code, like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109570. --- libio/stdio.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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, This function is a possible cancellation point and therefore not marked with __THROW. */ -extern int fclose (FILE *__stream); +extern int fclose (FILE *__stream) __nonnull ((1)); #undef __attr_dealloc_fclose #define __attr_dealloc_fclose __attr_dealloc (fclose, 1) @@ -269,7 +269,7 @@ extern FILE *fopen (const char *__restrict __filename, marked with __THROW. */ extern FILE *freopen (const char *__restrict __filename, const char *__restrict __modes, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream) __wur __nonnull ((3)); #else # ifdef __REDIRECT extern FILE *__REDIRECT (fopen, (const char *__restrict __filename, @@ -290,7 +290,7 @@ extern FILE *fopen64 (const char *__restrict __filename, __attribute_malloc__ __attr_dealloc_fclose __wur; extern FILE *freopen64 (const char *__restrict __filename, const char *__restrict __modes, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream) __wur __nonnull ((3)); #endif #ifdef __USE_POSIX -- 2.40.0