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/98918] New: Analyzer false positives due to sm-state involving UNKNOWN pointers
Date: Mon, 01 Feb 2021 15:17:52 +0000 [thread overview]
Message-ID: <bug-98918-4@http.gcc.gnu.org/bugzilla/> (raw)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98918
Bug ID: 98918
Summary: Analyzer false positives due to sm-state involving
UNKNOWN pointers
Product: gcc
Version: 11.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: ---
Reported to me via email:
> gcc -fanalyzer for the sample code below gives false positive results.
> If I remove field ref from struct marker, no problem is reported.
test.c
======
#include <stdlib.h>
struct marker {
struct marker *next;
void *ref;
};
struct data {
struct marker *marker;
};
void data_free(struct data d)
{
struct marker *nm, *m;
m = d.marker;
while (m) {
nm = m->next;
free(m->ref);
free(m);
m = nm;
}
}
$ gcc test.c -fanalyzer -c
test.c: In function ‘data_free’:
test.c:17:20: warning: use after ‘free’ of ‘m’ [CWE-416]
[-Wanalyzer-use-after-free]
17 | nm = m->next;
| ~~~^~~~~~~~~
‘data_free’: events 1-18
|
| 16 | while (m) {
| | ^
| | |
| | (1) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (3) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (5) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (7) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (10) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (12) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (14) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (16) following ‘true’ branch (when ‘m’ is
non-NULL)...
| 17 | nm = m->next;
| | ~~~~~~~~~~~~
| | |
| | (2) ...to here
| | (4) ...to here
| | (6) ...to here
| | (8) ...to here
| | (11) ...to here
| | (13) ...to here
| | (15) ...to here
| | (17) ...to here
| | (18) use after ‘free’ of ‘m’; freed at (9)
| 18 | free(m->ref);
| 19 | free(m);
| | ~~~~~~~
| | |
| | (9) freed here
|
test.c:18:17: warning: double-‘free’ of ‘*m.ref’ [CWE-415]
[-Wanalyzer-double-free]
18 | free(m->ref);
| ^~~~~~~~~~~~
‘data_free’: events 1-16
|
| 16 | while (m) {
| | ^
| | |
| | (1) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (3) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (5) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (8) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (10) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (12) following ‘true’ branch (when ‘m’ is
non-NULL)...
| | (14) following ‘true’ branch (when ‘m’ is
non-NULL)...
| 17 | nm = m->next;
| | ~~~~~~~~~~~~
| | |
| | (2) ...to here
| | (4) ...to here
| | (6) ...to here
| | (9) ...to here
| | (11) ...to here
| | (13) ...to here
| | (15) ...to here
| 18 | free(m->ref);
| | ~~~~~~~~~~~~
| | |
| | (7) first ‘free’ here
| | (16) second ‘free’ here; first ‘free’ was
at (7)
|
next reply other threads:[~2021-02-01 15:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-01 15:17 dmalcolm at gcc dot gnu.org [this message]
2021-02-01 15:20 ` [Bug analyzer/98918] " dmalcolm at gcc dot gnu.org
2021-02-01 15:23 ` [Bug analyzer/98918] [11 Regression] " dmalcolm at gcc dot gnu.org
2021-02-01 20:14 ` cvs-commit at gcc dot gnu.org
2021-02-01 20:17 ` 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-98918-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).