From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 59E8A3973013; Fri, 8 May 2020 15:03:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59E8A3973013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588950230; bh=qFtj8p1HzBwYUSer6TxeTMlCRWVyJbvOP23rvhRAgL0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xGUJRj2owz5vOaav3sM0arzVP6QLcjYHTeoNESxR4dihZ0AsTMGzxdG+te22b+hfi gNPRI7Twulgjf+pFCkZ2eZ3uQfuEBuz0q/4UEWqUh8R2gIeO/vd0qSwHB4EjbgRPPW S1YlBPu7G7Q0Mnx5RZzrT/TxlHW8rb3Vj2ojH/VY= From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/94851] -fanalyzer erroneously reporting NULL dereference - simple test case attached Date: Fri, 08 May 2020 15:03:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED 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: short_desc bug_status cf_reconfirmed_on everconfirmed Message-ID: In-Reply-To: References: 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, 08 May 2020 15:03:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94851 David Malcolm changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|-fanalyzer erroniously |-fanalyzer erroneously |reporting NULL dereference |reporting NULL dereference |- simple test case attached |- simple test case attached Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2020-05-08 Ever confirmed|0 |1 --- Comment #2 from David Malcolm --- Thanks for filing this bug. It does indeed look like a false positive. With -fanalyzer-verbosity=3D3 I get this output: ---------------------------------------------------------------------- $ ./xgcc -B. -c -fanalyzer t.c -O2 -fanalyzer-verbosity=3D3 t.c: In function =E2=80=98pamark=E2=80=99: t.c:48:19: warning: dereference of NULL =E2=80=98last=E2=80=99 [CWE-690] [-Wanalyzer-null-dereference] 48 | last->m_next =3D p; | ~~~~~~~~~~~~~~~^~~ =E2=80=98pamark=E2=80=99: events 1-5 | | 28 | while(p !=3D (AMARK*)NULL && p->m_name !=3D (char)c) { | | ^ | | | | | (1) following =E2=80=98false=E2=80=99 branch (when =E2= =80=98p=E2=80=99 is NULL)... |...... | 33 | if(p !=3D (AMARK*) NULL) { | | ~=20=20=20 | | | | | (2) ...to here | | (3) following =E2=80=98false=E2=80=99 branch (when =E2=80= =98p=E2=80=99 is NULL)... |...... | 40 | if((p =3D (AMARK*) malloc(sizeof(AMARK))) =3D=3D (AMARK*) NU= LL) | | ~ ~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (4) ...to here | | (5) following =E2=80=98false=E2=80=99 branch (when =E2=80= =98p=E2=80=99 is non-NULL)... | =E2=80=98pamark=E2=80=99: event 6 | | 43 | p->m_next =3D (AMARK*) NULL; | | ^ | | | | | (6) ...to here | =E2=80=98pamark=E2=80=99: events 7-10 | | ---------------------------------------------------------------------- It's considering the case where at: AMARK* p =3D curbp->b_amark; AMARK* last =3D curbp->b_amark; both pointers are NULL. I'm not sure why it's filtered those events at the default verbosity level. It's also not printing events 7-10 for some reason, but with -fdiagnostics-path-format=3Dseparate-events they show up as: t.c:43:13: note: (7) =E2=80=98last=E2=80=99 is NULL t.c:45:5: note: (8) following =E2=80=98false=E2=80=99 branch... 45 | if(curbp->b_amark =3D=3D (AMARK*) NULL) | ^ t.c:48:19: note: (9) ...to here 48 | last->m_next =3D p; | ~~~~~~~~~~~~~~~^~~ t.c:48:19: note: (10) dereference of NULL =E2=80=98last=E2=80=99 However, it seems to have lost the fact that "curbp->b_amark =3D=3D NULL" a= t event (8); hence a false positive. I've tried to simplify the reproducer but have had no success so far.=