From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 945AF3857C71; Mon, 22 Feb 2021 10:32:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 945AF3857C71 From: "rjones at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99196] New: GCC analyzer doesn't know that error (code != 0, ...) exits the program Date: Mon, 22 Feb 2021 10:32:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rjones at redhat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2021 10:32:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99196 Bug ID: 99196 Summary: GCC analyzer doesn't know that error (code !=3D 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/f19fd566f6387ce7e4d82409528c9= dde374d25e0/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=3Danalyzer-null-argument] 113 | len =3D strlen (str); | ^~~~~~~~~~~~ 'read_error_file': events 1-7 | | 109 | if (str =3D=3D NULL) { | | ^ | | | | | (1) following 'true' branch (when 'str' is NULL)... | 110 | str =3D strdup ("(no error)"); | | ~~~ ~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (3) allocated here | | (2) ...to here | 111 | if (str =3D=3D 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 =3D 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 =3D=3D 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=