public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	 libc-alpha@sourceware.org
Subject: Re: [PATCH] libio: Add __nonnull for FILE * arguments of fclose and freopen
Date: Sat, 22 Apr 2023 15:32:37 +0800	[thread overview]
Message-ID: <211642b165735b9271aa505bc11bf0430b0205d0.camel@xry111.site> (raw)
In-Reply-To: <6486b199-adec-57c7-4a08-4a98fd57ab0d@linaro.org>

On Fri, 2023-04-21 at 10:00 -0300, Adhemerval Zanella Netto wrote:
> 
> 
> 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.

Thanks, please commit it if there is no objections.  Or may I get a
write after approve access for glibc.git?

> 
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> 
> > ---
> >  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

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-04-22  7:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21  6:21 Xi Ruoyao
2023-04-21 13:00 ` Adhemerval Zanella Netto
2023-04-22  7:32   ` Xi Ruoyao [this message]
2023-05-16  2:50 ` Ping: " Xi Ruoyao
2023-05-16 10:04   ` Adhemerval Zanella Netto
2023-05-22 12:36     ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=211642b165735b9271aa505bc11bf0430b0205d0.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).