fileno() Does Not Check for NULL

Joel Sherrill
Wed Feb 17 15:57:44 GMT 2021


In looking at Coverity issues, we are seeing that calls to fileno() are
getting flagged as potential NULL dereferences. Looking at the POSIX
definition, it seems that it should return an -1/EBADF because NULL isn't a
valid stream.

I know there is a pattern of not having NULL checks assuming that the
environment would catch the fault. But in the embedded environments newlib
is used in, there isn't anything to catch the fault.

I don't want to add application code to check for a NULL before calling a
standard method that isn't robustly checking its arguments.

I don't know if it would address the Coverity issue but would adding the
nonnull attribute on more methods be acceptable and help? It is defined and
used in a few places now.

What's the right approach to addressing this?



More information about the Newlib mailing list