fileno() Does Not Check for NULL
Joel Sherrill <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAF9ehCUbF=FvBL5eNZibenTyVHYknfoKZnDnP7LuAXbpYeXSqQ@mail.gmail.com> |
Hi 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. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html 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? Thanks. --joel