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/113333] analyzer: False positives with calloc()
Date: Thu, 11 Jan 2024 19:43:19 +0000	[thread overview]
Message-ID: <bug-113333-4-K39YeAmyGC@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113333-4@http.gcc.gnu.org/bugzilla/>

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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-11
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug.

Looking at trunk with:

extern void __analyzer_describe (int verbosity, ...);
extern void __analyzer_eval (int);

#include <stdlib.h>
char **f(void) {
    char **vec = calloc(1, sizeof(char *));
    if (vec)
        {
           char **p=vec;       
          __analyzer_describe (0, p);
          __analyzer_describe (0, *p);
          __analyzer_eval (*p == 0);
        }
    return vec;
}

https://gcc.godbolt.org/z/z3vnxbTaT

source>: In function 'f':
<source>:10:11: warning: svalue: '&HEAP_ALLOCATED_REGION(14)'
   10 |           __analyzer_describe (0, p);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:11:11: warning: svalue: 'CAST(char *, REPEATED(outer_size: (long
unsigned int)8, inner_val: (char)0))'
   11 |           __analyzer_describe (0, *p);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:12:11: warning: UNKNOWN
   12 |           __analyzer_eval (*p == 0);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~

i.e. the analyzer "sees" that *p is the 0-byte repeated 8 times, cast to a char
*, but doesn't simplify that to just a NULL pointer.

I'm looking at a fix.

  reply	other threads:[~2024-01-11 19:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 10:01 [Bug analyzer/113333] New: " buczek at molgen dot mpg.de
2024-01-11 19:43 ` dmalcolm at gcc dot gnu.org [this message]
2024-01-16  0:02 ` [Bug analyzer/113333] " cvs-commit at gcc dot gnu.org
2024-01-16  0:09 ` dmalcolm at gcc dot gnu.org
2024-01-16  8:05 ` buczek at molgen dot mpg.de
2024-04-14  5:04 ` [Bug analyzer/113333] [11/12/13 Regression] " pinskia at gcc dot gnu.org
2024-05-09 17:11 ` cvs-commit at gcc dot gnu.org
2024-05-09 17:52 ` [Bug analyzer/113333] [11/12 " 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-113333-4-K39YeAmyGC@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).