libio: Add nonnull attribute for most FILE * arguments in stdio.h
commit64b1a44183a3094672ed304532bedb9acc707554
authorXi Ruoyao <xry111@xry111.site>
Mon, 25 Sep 2023 11:53:26 +0000 (25 19:53 +0800)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Wed, 27 Sep 2023 00:11:38 +0000 (26 20:11 -0400)
tree41131e52fd02f763e2ab83cb9967386f4c40a515
parent6b695e5c628734b9801fcf53149687cb4fe6926e
libio: Add nonnull attribute for most FILE * arguments in stdio.h

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.

fflush and fflush_unlocked are well defined when __stream is NULL so
they are 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 did not segfault.  But the standard disallow __stream to be empty
here, so nonnull attribute is also added for them.  Note that this may
blow up some old code already subtly broken.

Also add __nonnull for _chk variants and __fortify_function versions for
them.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
libio/bits/stdio2-decl.h
libio/bits/stdio2.h
libio/stdio.h