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/109060] New: -Wanalyzer-deref-before-check false positives seen in haproxy's cfgparse.c: parse_process_number
Date: Tue, 07 Mar 2023 21:45:55 +0000	[thread overview]
Message-ID: <bug-109060-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 109060
           Summary: -Wanalyzer-deref-before-check false positives seen in
                    haproxy's cfgparse.c: parse_process_number
           Product: gcc
           Version: 13.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: ---

Created attachment 54603
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54603&action=edit
Reproducer

https://godbolt.org/z/qnd1TrWsh

Trunk falsely emits this on the attached file:

$ ./xgcc -B. -S -fanalyzer -Wall ../../src/haproxy-cfgparse.c 
../../src/haproxy-cfgparse.c: In function ‘parse_process_number’:
../../src/haproxy-cfgparse.c:58:21: warning: check of ‘dash’ for NULL after
already dereferencing it [-Wanalyzer-deref-before-check]
   58 |       if (*p == '-' && !dash)
      |           ~~~~~~~~~~^~~~~~~~
  ‘parse_process_number’: events 1-16
    |
    |   47 |   if (strcmp(arg, "all") == 0)
    |      |      ~^~~~~~~~~~~~~~~~~~
    |      |      ||
    |      |      |(1) pointer ‘dash’ is dereferenced here
    |      |      (2) following ‘false’ branch (when the strings are
non-equal)...
    |   48 |     *proc |= ~0UL;
    |   49 |   else if (strcmp(arg, "odd") == 0)
    |      |           ~~~~~~~~~~~~~~~~~~~
    |      |           ||
    |      |           |(3) ...to here
    |      |           (4) following ‘false’ branch (when the strings are
non-equal)...
    |   50 |     *proc |= ~0UL / 3UL;
    |   51 |   else if (strcmp(arg, "even") == 0)
    |      |           ~~~~~~~~~~~~~~~~~~~~
    |      |           ||
    |      |           |(5) ...to here
    |      |           (6) following ‘false’ branch (when the strings are
non-equal)...
    |......
    |   54 |     const char *p, *dash = ((void*)0);
    |      |                     ~~~~
    |      |                     |
    |      |                     (7) ...to here
    |......
    |   57 |     for (p = arg; *p; p++) {
    |      |                   ~
    |      |                   |
    |      |                   (8) following ‘true’ branch...
    |      |                   (12) following ‘true’ branch...
    |   58 |       if (*p == '-' && !dash)
    |      |          ~~~~~~~~~~~~~~~~~~~
    |      |          ||         |
    |      |          ||         (10) following ‘true’ branch (when ‘dash’ is
NULL)...
    |      |          ||         (15) ...to here
    |      |          ||         (16) pointer ‘dash’ is checked for NULL here
but it was already dereferenced at (1)
    |      |          |(9) ...to here
    |      |          |(13) ...to here
    |      |          (14) following ‘true’ branch...
    |   59 |         dash = p;
    |      |         ~~~~~~~~
    |      |              |
    |      |              (11) ...to here
    |
../../src/haproxy-cfgparse.c:68:8: warning: check of ‘dash’ for NULL after
already dereferencing it [-Wanalyzer-deref-before-check]
   68 |     if (dash)
      |        ^
  ‘parse_process_number’: events 1-12
    |
    |   47 |   if (strcmp(arg, "all") == 0)
    |      |      ~^~~~~~~~~~~~~~~~~~
    |      |      ||
    |      |      |(1) pointer ‘dash’ is dereferenced here
    |      |      (2) following ‘false’ branch (when the strings are
non-equal)...
    |   48 |     *proc |= ~0UL;
    |   49 |   else if (strcmp(arg, "odd") == 0)
    |      |           ~~~~~~~~~~~~~~~~~~~
    |      |           ||
    |      |           |(3) ...to here
    |      |           (4) following ‘false’ branch (when the strings are
non-equal)...
    |   50 |     *proc |= ~0UL / 3UL;
    |   51 |   else if (strcmp(arg, "even") == 0)
    |      |           ~~~~~~~~~~~~~~~~~~~~
    |      |           ||
    |      |           |(5) ...to here
    |      |           (6) following ‘false’ branch (when the strings are
non-equal)...
    |......
    |   54 |     const char *p, *dash = ((void*)0);
    |      |                     ~~~~
    |      |                     |
    |      |                     (7) ...to here
    |......
    |   57 |     for (p = arg; *p; p++) {
    |      |                   ~
    |      |                   |
    |      |                   (8) following ‘true’ branch...
    |   58 |       if (*p == '-' && !dash)
    |      |           ~~~~~~~~~~~~~~~~~~
    |      |           |         |
    |      |           |         (10) following ‘true’ branch (when ‘dash’ is
NULL)...
    |      |           (9) ...to here
    |   59 |         dash = p;
    |      |         ~~~~~~~~
    |      |              |
    |      |              (11) ...to here
    |......
    |   68 |     if (dash)
    |      |        ~
    |      |        |
    |      |        (12) pointer ‘dash’ is checked for NULL here but it was
already dereferenced at (1)
    |

             reply	other threads:[~2023-03-07 21:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 21:45 dmalcolm at gcc dot gnu.org [this message]
2023-03-10 13:22 ` [Bug analyzer/109060] " cvs-commit at gcc dot gnu.org
2023-03-10 13:58 ` 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-109060-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).