public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Xi Ruoyao <xry111@xry111.site>, libc-alpha@sourceware.org
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	Carlos O'Donell <carlos@redhat.com>
Subject: Re: [PATCH] libio: Add nonnull attribute for most FILE * arguments in stdio.h
Date: Thu, 18 May 2023 20:56:13 +0200	[thread overview]
Message-ID: <c4fb7dd2-81d3-e68b-d1c8-030014f5675d@gmail.com> (raw)
In-Reply-To: <d96fd93d-4e49-111b-175d-314ff38cc9f1@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3605 bytes --]

On 5/18/23 20:06, Alex Colomar wrote:
> Hi Xi!
> 
> On 5/18/23 19:25, Xi Ruoyao via Libc-alpha wrote:
>> During the review of a GCC analyzer test case, we found most stdio
>> functions accepting a FILE * argument expect it to be nonnull and just
>> segfault when the argument is NULL.  Add nonnull attribute for them.
>>
>> setbuf is well defined when __stream is NULL so it's not touched.
>>
>> For fputs, fgets, fread, fwrite, fprintf, vfprintf, and their unlocked
>> version, if __stream is empty but there is nothing to read or write,
>> they don't segfault and I'm not sure if the standard allows such a use
>> so I left them out.
>> ---
>>   libio/stdio.h | 119 ++++++++++++++++++++++++++------------------------
>>   1 file changed, 62 insertions(+), 57 deletions(-)
>>
>> diff --git a/libio/stdio.h b/libio/stdio.h
>> index 4cf9f1c012..ae3d7295d4 100644
>> --- a/libio/stdio.h
>> +++ b/libio/stdio.h
>> @@ -232,7 +232,7 @@ extern char *tempnam (const char *__dir, const 
>> char *__pfx)
>>      This function is a possible cancellation point and therefore not
>>      marked with __THROW.  */
>> -extern int fflush (FILE *__stream);
>> +extern int fflush (FILE *__stream) __nonnull ((1));
> 
> flush(NULL) is well defined.  It flushes all streams that can be
> flushed.  This reminds me that I should document that in the SYNOPSIS
> section of the manual page; an oversight on my side.

I just pushed this:

<https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=cd03c9b8d1f4d43ab7b010d02287dec1805ada34>

commit cd03c9b8d1f4d43ab7b010d02287dec1805ada34 (HEAD -> master, 
korg/master, alx/main, alx/HEAD, main)
Author: Alejandro Colomar <alx@kernel.org>
Date:   Thu May 18 20:53:14 2023 +0200

     fflush.3, unlocked_stdio.3: SYNOPSIS: The streams can be null

     Cc: Xi Ruoyao <xry111@xry111.site>
     Signed-off-by: Alejandro Colomar <alx@kernel.org>

diff --git a/man3/fflush.3 b/man3/fflush.3
index 327786cef..2098bba08 100644
--- a/man3/fflush.3
+++ b/man3/fflush.3
@@ -25,7 +25,7 @@ Standard C library
  .nf
  .B #include <stdio.h>
  .PP
-.BI "int fflush(FILE *" stream );
+.BI "int fflush(FILE *_Nullable " stream );
  .fi
  .SH DESCRIPTION
  For output streams,
diff --git a/man3/unlocked_stdio.3 b/man3/unlocked_stdio.3
index faab29f06..feed708db 100644
--- a/man3/unlocked_stdio.3
+++ b/man3/unlocked_stdio.3
@@ -23,7 +23,7 @@ Standard C library
  .BI "int feof_unlocked(FILE *" stream );
  .BI "int ferror_unlocked(FILE *" stream );
  .BI "int fileno_unlocked(FILE *" stream );
-.BI "int fflush_unlocked(FILE *" stream );
+.BI "int fflush_unlocked(FILE *_Nullable " stream );
  .PP
  .BI "int fgetc_unlocked(FILE *" stream );
  .BI "int fputc_unlocked(int " c ", FILE *" stream );

> 
>>   #ifdef __USE_MISC
>>   /* Faster versions when locking is not required.
>> @@ -241,7 +241,7 @@ extern int fflush (FILE *__stream);
>>      cancellation point.  But due to similarity with an POSIX interface
>>      or due to the implementation it is a cancellation point and
>>      therefore not marked with __THROW.  */
>> -extern int fflush_unlocked (FILE *__stream);
>> +extern int fflush_unlocked (FILE *__stream) __nonnull ((1));
> 
> Without checking, I'll guess that fflush_unlocked(NULL) is also well
> defined.
> 
> I didn't see any other similar cases, but I may have missed some; I
> didn't revise them all thoroughly; please check.
> 

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2023-05-18 18:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 17:25 Xi Ruoyao
2023-05-18 18:06 ` Alex Colomar
2023-05-18 18:29   ` Alex Colomar
2023-05-19  4:13     ` Xi Ruoyao
2023-05-19  5:21       ` Xi Ruoyao
2023-05-19 12:40         ` Alejandro Colomar
2023-05-19 13:03           ` Xi Ruoyao
2023-05-19 13:07             ` Alejandro Colomar
2023-05-18 18:56   ` Alejandro Colomar [this message]

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=c4fb7dd2-81d3-e68b-d1c8-030014f5675d@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=xry111@xry111.site \
    /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).