public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/96894] New: Analyzer assumes pointer is NULL, even if pointer was tested to be non-null before
@ 2020-09-02  7:44 vries at gcc dot gnu.org
  2020-09-02 19:14 ` [Bug analyzer/96894] " dmalcolm at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2020-09-02  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96894
           Summary: Analyzer assumes pointer is NULL, even if pointer was
                    tested to be non-null before
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Created attachment 49174
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49174&action=edit
fibheap.c, preprocessed version from gdb/binutils master

Using gcc-11 (SUSE Linux) 11.0.0 20200901 (experimental) [revision
b1850c617b14eedaf60b358f3b7d4707cff73b8a].

Invoked like this:
...
$ gcc-11 fibheap.c -fanalyzer -S
...

We have:
...
fibheap.c: In function ‘fibnode_remove’:
fibheap.c:3122:42: warning: dereference of NULL ‘*(node).parent’ [CWE-690]
[-Wanalyzer-null-dereference]
 3122 |                           && node->parent->child == node)
      |                              ~~~~~~~~~~~~^~~~~~~
...

Looking at the source code, we have:
...
  3118    if (node->parent !=
  3119
  3120                       ((void *)0)
  3121
  3122                            && node->parent->child == node)
  3123      node->parent->child = ret;
...

So, just before dereferencing node->parent, we check that it's non-null, so the
warning that node->parent is dereferenced while it's null makes no sense.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-12 21:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-02  7:44 [Bug analyzer/96894] New: Analyzer assumes pointer is NULL, even if pointer was tested to be non-null before vries at gcc dot gnu.org
2020-09-02 19:14 ` [Bug analyzer/96894] " dmalcolm at gcc dot gnu.org
2021-02-14 17:25 ` dimhen at gmail dot com
2021-03-03 18:37 ` [Bug analyzer/96894] State explosion on gdb's fibheap.c dmalcolm at gcc dot gnu.org
2021-03-12 21:52 ` dmalcolm at gcc dot gnu.org

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).