public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "antonio.chirizzi at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/99028] New: diagnostic path is too verbose
Date: Tue, 09 Feb 2021 16:01:03 +0000	[thread overview]
Message-ID: <bug-99028-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 99028
           Summary: diagnostic path is too verbose
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: antonio.chirizzi at gmail dot com
  Target Milestone: ---

Created attachment 50151
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50151&action=edit
Tar.gz file which contains the path.c file (from the git source code repo)

When analysing a path for a possible null dereference, in the straight forward
case, there should be no need to show the verbose description of how it can
lead to a null dereference.

Take this case where a call to malloc is followed by the usage of the returned
pointer:

In function ‘add_to_trie’:
path.c:175:28: warning: dereference of possibly-NULL ‘child’ [CWE-690]
[-Wanalyzer-possible-null-dereference]
  175 |                 child->len = root->len - i - 1;
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
  ‘add_to_trie’: events 1-8
    |
    |  157 |         if (!*key) {
    |      |            ^
    |      |            |
    |      |            (1) following ‘false’ branch...
    |......
    |  164 |         for (i = 0; i < root->len; i++) {
    |      |              ~~~~~  ~~~~~~~~~~~~~
    |      |                |      |
    |      |                |      (3) following ‘true’ branch...
    |      |                (2) ...to here
    |  165 |                 if (root->contents[i] == key[i])
    |      |                    ~~~~~~~~~~~~~~~
    |      |                    |    |
    |      |                    |    (4) ...to here
    |      |                    (5) following ‘false’ branch...
    |......
    |  172 |                 child = malloc(sizeof(*child));
    |      |                         ~~~~~~~~~~~~~~~~~~~~~~
    |      |                         |
    |      |                         (6) ...to here
    |      |                         (7) this call could return NULL
    |......
    |  175 |                 child->len = root->len - i - 1;
    |      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                            |
    |      |                            (8) ‘child’ could be NULL: unchecked
value from (7)
    |


I am attaching the source code which demonstrates this.

Use only "gcc -fanalyzer -c path.c"

             reply	other threads:[~2021-02-09 16:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 16:01 antonio.chirizzi at gmail dot com [this message]
2021-02-09 16:39 ` [Bug analyzer/99028] " dmalcolm at gcc dot gnu.org
2021-02-09 17:19 ` 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-99028-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).