From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by sourceware.org (Postfix) with ESMTPS id B37423858C83 for ; Fri, 21 Apr 2023 13:00:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B37423858C83 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-oo1-xc34.google.com with SMTP id 006d021491bc7-546de76c23eso1042951eaf.0 for ; Fri, 21 Apr 2023 06:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682082007; x=1684674007; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0V6IIaqWhZvDoM5Eht30ezqDvqh0kwTD5CqoOSFlfdo=; b=smCY3SySURgEzTYt9mqeey9ZL7ajbzLxOzWXlDeTwwNf/El+51A0PDw3plH2OoPMTi T5BUvz9rgQV43Eue5HssRFwvP9EDw5sqNEo0EMTTPrd3BGTpOyDoqIWagIyUpG+BFKre qkv6DRcxunzoTF5GfghseMNr6N7E6Vcm2ri5Rr1gR19BhfdZEhpV1T0XnFcyQRWFacFU 0kK7kkD1s38Cxd8dX3VCJp0Y2EmfnfsfTmxDSQDzxdlv0Kvuk1fMNg/J0g72tDFSmBAd vuXVTJJhsw6Y6gNk7sn5hnke+JCUkAnw0er0zL2Ql5X9qD3MvxNrbqR0luvwp4AhAJpS 0nmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682082007; x=1684674007; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0V6IIaqWhZvDoM5Eht30ezqDvqh0kwTD5CqoOSFlfdo=; b=LoqkUL8qMDqol0l6EwGN+7Ii+zRnIDluG/BSvF4ZlwFl70ZVbC/jRCN9M9OrGnqDvt g/OEGSsBivOfiO3OVJLqj4W8xuJP36L36+/fY0Kopu9CLgHLlW6YCbDNBEn9s1QzvLc9 0N6EQ4LRbQ7BHPRpE4hfjN7ETf6fFIg/s0EEH5b47NFxFv9O+IKWPj2JqH0cQQOe1kgv 3X6NDD6KntwP2thQFrjRi6mVb7ZTXnrFB7RPeLnvH7pCRBDpzmnKdWZEhHa/fKjBWtVb 9daawILhxNPlbWJljaDH7VRIDGiTh/gXp+WtEW4zHaxGPNsL0fxXuTweUbqSiIpMXELU D+RQ== X-Gm-Message-State: AAQBX9eun/Fp81DEbGJ6wBsUrE35KiyO1npuZI9RzZpT+NrOhAwlJ7BT rmTo5DuR3/2kl/Z9FbIJQdSFOV1GLhuxIjNGvvzWHA== X-Google-Smtp-Source: AKy350Ygpptq4ja+VwS+GZcR1brDG2bG9vFcqcpm2DzbJKUtN5BTlL3r3VJ7Gim9zdxU43mePkpdow== X-Received: by 2002:a4a:e8c8:0:b0:533:8901:fc93 with SMTP id h8-20020a4ae8c8000000b005338901fc93mr1111386ooe.9.1682082006932; Fri, 21 Apr 2023 06:00:06 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c3:333:20b7:b016:1b7f:fd25? ([2804:1b3:a7c3:333:20b7:b016:1b7f:fd25]) by smtp.gmail.com with ESMTPSA id 123-20020a4a0d81000000b00547372059afsm1614491oob.4.2023.04.21.06.00.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Apr 2023 06:00:06 -0700 (PDT) Message-ID: <6486b199-adec-57c7-4a08-4a98fd57ab0d@linaro.org> Date: Fri, 21 Apr 2023 10:00:03 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] libio: Add __nonnull for FILE * arguments of fclose and freopen Content-Language: en-US To: Xi Ruoyao , libc-alpha@sourceware.org References: <20230421062133.2084910-1-xry111@xry111.site> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230421062133.2084910-1-xry111@xry111.site> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,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: 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. 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. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > 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