public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99196] New: GCC analyzer doesn't know that error (code != 0, ...) exits the program
@ 2021-02-22 10:32 rjones at redhat dot com
  2021-02-22 15:22 ` [Bug analyzer/99196] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rjones at redhat dot com @ 2021-02-22 10:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99196

            Bug ID: 99196
           Summary: GCC analyzer doesn't know that error (code != 0, ...)
                    exits the program
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rjones at redhat dot com
  Target Milestone: ---

https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/tar.c#L108

tar.c: In function 'read_error_file':
tar.c:113:11: error: use of NULL 'str' where non-null expected [CWE-476]
[-Werror=analyzer-null-argument]
  113 |     len = strlen (str);
      |           ^~~~~~~~~~~~
  'read_error_file': events 1-7
    |
    |  109 |   if (str == NULL) {
    |      |      ^
    |      |      |
    |      |      (1) following 'true' branch (when 'str' is NULL)...
    |  110 |     str = strdup ("(no error)");
    |      |     ~~~   ~~~~~~~~~~~~~~~~~~~~~
    |      |     |     |
    |      |     |     (3) allocated here
    |      |     (2) ...to here
    |  111 |     if (str == NULL)
    |      |        ~
    |      |        |
    |      |        (4) assuming 'str' is NULL
    |      |        (5) following 'true' branch (when 'str' is NULL)...
    |  112 |       error (EXIT_FAILURE, errno, "strdup"); /* XXX */
    |      |       ~~~~~
    |      |       |
    |      |       (6) ...to here
    |  113 |     len = strlen (str);
    |      |           ~~~~~~~~~~~~
    |      |           |
    |      |           (7) argument 1 ('str') NULL where non-null expected
    |
In file included from ../gnulib/lib/string.h:41,
                 from tar.c:23:
/usr/include/string.h:391:15: note: argument 1 of 'strlen' must be non-null
  391 | extern size_t strlen (const char *__s)
      |               ^~~~~~
cc1: all warnings being treated as errors

In the original code if str == NULL, error (EXIT_FAILURE, ...) is
called which exits the program.  Therefore strlen (NULL) cannot
be called so the warning is bogus.

https://www.man7.org/linux/man-pages/man3/error.3.html

       "If status has a nonzero value, then error() calls exit(3) to
       terminate the program using the given value as the exit status."

gcc-11.0.0-0.19.fc35.x86_64

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-02-22 23:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 10:32 [Bug c/99196] New: GCC analyzer doesn't know that error (code != 0, ...) exits the program rjones at redhat dot com
2021-02-22 15:22 ` [Bug analyzer/99196] " msebor at gcc dot gnu.org
2021-02-22 16:53 ` dmalcolm at gcc dot gnu.org
2021-02-22 17:18 ` rjones at redhat dot com
2021-02-22 23:47 ` cvs-commit at gcc dot gnu.org
2021-02-22 23:48 ` dmalcolm at gcc dot gnu.org

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).