public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "avarab at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-105285-4-xZa41BJbN8@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105285-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105285 --- Comment #1 from Ævar Arnfjörð Bjarmason <avarab at gmail dot com> --- Created attachment 52814 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52814&action=edit 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 top 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 >= r_size) /* (28) following ‘true’ branch (when ‘off >= r_size’)... */ + return 0; + if (off + sz > r_size) { sz = r_size - off; } @@ -288,13 +291,14 @@ int reader_init_block_reader(struct reftable_reader *r, struct block_reader *br, uint32_t header_off = next_off ? 0 : header_size(r->version); int32_t block_size = 0; - if (next_off >= r_size) + if (next_off >= r_size) /* (24) following ‘false’ branch (when ‘next_off < r_size’)... */ return 1; err = reader_get_block(&block, &r->source, next_off, guess_block_size, r_size); - if (err < 0) + if (err < 0) /* (31) following ‘false’ branch (when ‘err >= 0’)... */ goto done; + /* We'll supposedly deference NULL block.data[0] here ... */ block_size = extract_block_size(block.data, &block_typ, next_off, r->version); if (block_size < 0) {
next prev parent reply other threads:[~2022-04-15 9:49 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-15 9:39 [Bug analyzer/105285] New: " avarab at gmail dot com 2022-04-15 9:49 ` avarab at gmail dot com [this message] 2022-04-15 9:54 ` [Bug analyzer/105285] " avarab at gmail dot com 2022-04-15 15:11 ` dmalcolm at gcc dot gnu.org 2022-04-27 17:56 ` dmalcolm at gcc dot gnu.org 2022-04-27 18:07 ` dmalcolm at gcc dot gnu.org 2022-04-27 18:08 ` dmalcolm at gcc dot gnu.org 2022-04-27 18:08 ` dmalcolm at gcc dot gnu.org 2022-04-27 19:24 ` dmalcolm at gcc dot gnu.org 2022-04-28 17:48 ` cvs-commit at gcc dot gnu.org 2022-04-28 17:51 ` cvs-commit at gcc dot gnu.org 2022-04-28 17:57 ` dmalcolm at gcc dot gnu.org 2022-07-27 21:55 ` cvs-commit at gcc dot gnu.org 2022-07-27 21:55 ` cvs-commit at gcc dot gnu.org 2022-07-27 22:09 ` dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105285-4-xZa41BJbN8@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).