public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109266] New: Wanalyzer-null-dereference does not warn when struct is at null
@ 2023-03-23 22:17 jg at jguk dot org
  2023-03-26 14:58 ` [Bug analyzer/109266] " dmalcolm at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jg at jguk dot org @ 2023-03-23 22:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109266
           Summary: Wanalyzer-null-dereference does not warn when struct
                    is at null
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Couldn't find an existing report for this.
Hope the very useful Analyzer can be enhanced to handle nullptr for structs.
Which means that when reading members of the struct they might be at 0x4 etc,
not directly 0x0

Analyzer does detect if the first 'int' in this struct at address nullptr is
read. If the code reads the bytes after in the struct, it doesn't identify that
0x4 address is also inaccessible.

Only way to ensure to get a warning is to copy the struct to a local variable
(before reading those bytes at offset 0x4 from the copy).

Try it live:
https://godbolt.org/z/9a611jvfM

-fanalyzer -Wall -O2

typedef struct a
{
    int b;
    char c[3];
} a_t;

void f(a_t * s)
{
    //s->b = 0;
    s->c[0] = 'b';
}

int main()
{
    a_t * s = nullptr;
    f(s);
}

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

end of thread, other threads:[~2023-03-31 21:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 22:17 [Bug analyzer/109266] New: Wanalyzer-null-dereference does not warn when struct is at null jg at jguk dot org
2023-03-26 14:58 ` [Bug analyzer/109266] " dmalcolm at gcc dot gnu.org
2023-03-26 21:08 ` jg at jguk dot org
2023-03-27 23:14 ` dmalcolm at gcc dot gnu.org
2023-03-27 23:22 ` dmalcolm at gcc dot gnu.org
2023-03-31 21:30 ` jg at jguk dot 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).