From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E780F3856DCE; Fri, 15 Apr 2022 09:39:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E780F3856DCE From: "avarab at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/105285] New: False positive with -Wanalyzer-null-dereference in git.git's reftable/reader.c Date: Fri, 15 Apr 2022 09:39:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: avarab at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm 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 attachments.created 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: Fri, 15 Apr 2022 09:39:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105285 Bug ID: 105285 Summary: False positive with -Wanalyzer-null-dereference in git.git's reftable/reader.c Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: avarab at gmail dot com Target Milestone: --- Created attachment 52813 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52813&action=3Dedit gcc -E of reftable/reader.c I didn't have time to come up with a nice isolated test case this time for $subject, sorry, but (maybe this is easier): git clone https://github.com/git/git/ cd git make CC=3Dgcc CFLAGS=3D-fanalyzer reftable/reader.o Or alternatively the gcc -E output that's attached, but most informative is= the patch I'll attach to git.git to work around this (as the code was pretty nonsensical anyway). Why do I think it's a false positive? It's code that's basically doing: struct x =3D { 0 }; /* "foo" member is NULL */ if (x >=3D 0) return 0; /* early abort */ [...] if (x >=3D 0) return 1; /* we don't init "x.foo" */ x.foo I.e. the analyzer thinks you can go through these two and for "x >=3D 0" to= be true the first time, and false the next, or the other way around. In this case the types didn't have "const" on them, but to make sure these *really* weren't being changed I added that in all the relevant places, but= it still complained. The warning was: reftable/reader.c: In function =E2=80=98extract_block_size=E2=80=99: reftable/reader.c:274:20: warning: dereference of NULL =E2=80=98data=E2=80= =99 [CWE-476] [-Wanalyzer-null-dereference] 274 | *typ =3D data[0]; | ~~~~^~~ Also, for the GCC 11.2 I have locally (I tested the warning on near-trunk G= CC 12.0) I got two different warnings from -fanalyzer, so this seems to be an = area that's seen active changes recently...=