From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 85D4C3857378; Fri, 15 Apr 2022 09:49:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85D4C3857378 From: "avarab at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/105285] False positive with -Wanalyzer-null-dereference in git.git's reftable/reader.c Date: Fri, 15 Apr 2022 09:49:43 +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: 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: attachments.created 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, 15 Apr 2022 09:49:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105285 --- Comment #1 from =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason --- Created attachment 52814 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52814&action=3Dedit A patch to git.git that works around the -fanalyzer false positive A fix to git.git to work around the analyzer false positive, this diff on t= op shows an annotated path through the program it thinks we'd take. 24 and 28 can't be true/false false/true, only false/false true/true. diff --git a/reftable/reader.c b/reftable/reader.c index ea66771165f..d3a4639d6ca 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -61,6 +61,9 @@ static int reader_get_block(struct reftable_block *dest, uint32_t sz, const uint64_t off, const uint64_t r_size) { + if (off >=3D r_size) /* (28) following =E2=80=98true=E2=80=99 branc= h (when =E2=80=98off >=3D r_size=E2=80=99)... */ + return 0; + if (off + sz > r_size) { sz =3D r_size - off; } @@ -288,13 +291,14 @@ int reader_init_block_reader(struct reftable_reader *= r, struct block_reader *br, uint32_t header_off =3D next_off ? 0 : header_size(r->version); int32_t block_size =3D 0; - if (next_off >=3D r_size) + if (next_off >=3D r_size) /* (24) following =E2=80=98false=E2=80=99= branch (when =E2=80=98next_off < r_size=E2=80=99)... */ return 1; err =3D reader_get_block(&block, &r->source, next_off, guess_block_= size, r_size); - if (err < 0) + if (err < 0) /* (31) following =E2=80=98false=E2=80=99 branch (when= =E2=80=98err >=3D 0=E2=80=99)... */ goto done; + /* We'll supposedly deference NULL block.data[0] here ... */=20 block_size =3D extract_block_size(block.data, &block_typ, next_off, r->version); if (block_size < 0) {=