public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/99671] New: RFE: analyzer could complain about ptr derefs that occur before the ptr is checked
Date: Fri, 19 Mar 2021 15:03:17 +0000	[thread overview]
Message-ID: <bug-99671-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99671

            Bug ID: 99671
           Summary: RFE: analyzer could complain about ptr derefs that
                    occur before the ptr is checked
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

See e.g. bug 80049, where we have code of the form


  expr = p->field;
  [...]
  if (p) ...

We could complain that 'p' has already been dereferenced before the check.
This might be implementable using sm-malloc: the "p->field" dereference
transitions "p" to non-null, and we could thus complain at the "if (p)" on
non-null if the transition was due to such a transition (rather than being
known to be non-null) - or perhaps a new state "assumed-non-null"?

PVS Studio complains about this:
  https://www.viva64.com/en/w/v595/
  https://www.viva64.com/en/examples/v595/
using CWE 476:
  https://cwe.mitre.org/data/definitions/476.html

             reply	other threads:[~2021-03-19 15:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 15:03 dmalcolm at gcc dot gnu.org [this message]
2022-11-09 14:00 ` [Bug analyzer/99671] " dmalcolm at gcc dot gnu.org
2022-11-09 22:26 ` dmalcolm at gcc dot gnu.org
2022-11-10 18:31 ` cvs-commit at gcc dot gnu.org
2022-11-10 18:49 ` dmalcolm at gcc dot gnu.org
2022-11-28 22:18 ` pinskia 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-99671-4@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: link
Be 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).