public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/99260] New: analyzer does not track outcomes of realloc
@ 2021-02-24 21:02 dmalcolm at gcc dot gnu.org
  2021-02-25  0:57 ` [Bug analyzer/99260] " cvs-commit at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2021-02-24 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99260
           Summary: analyzer does not track outcomes of realloc
           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: ---

The analyzer currently has no knowledge of the behavior of "realloc" (leading
e.g. to bug 99193).

For example, it currently fails to issue a warning for the classic
"self-assignment realloc" gotcha, code of the form:
  p = realloc (p, 4096);

e.g.
  void *p = malloc (1024);
  p = realloc (p, 4096);
  free (p);

which ought to be reported as a leak (for the case where the realloc fails,
losing the ptr to the original buffer).

Ideally, the analyzer would track various possible outcomes of realloc:
  - buffer grew successfully in-place
  - buffer was successfully moved to a larger allocation
  - buffer was successfully contracted
  - realloc failed, returning NULL, without freeing existing buffer.
or simply:
  - success: non-NULL is returned
  - failure: NULL is returned, existing buffer is not freed.

Unfortunately, the analyzer is currently structured so that each call
statement can only have at most one successor state; there is no
way to "bifurcate" the state, or have N-way splits into multiple
outcomes.  The existing "on_stmt" code works on a copy of the next
state, updating it in place, rather than copying it and making any
necessary changes.  I did this as an optimization to avoid unnecessary
copying of state objects, but it makes it hard to support multiple
outcomes.  (ideally our state objects would be immutable and thus
support trivial copying, alternatively, C++11 move semantics may
help here)

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

end of thread, other threads:[~2021-08-31  9:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 21:02 [Bug analyzer/99260] New: analyzer does not track outcomes of realloc dmalcolm at gcc dot gnu.org
2021-02-25  0:57 ` [Bug analyzer/99260] " cvs-commit at gcc dot gnu.org
2021-03-19 14:14 ` dmalcolm at gcc dot gnu.org
2021-03-19 14:19 ` dmalcolm at gcc dot gnu.org
2021-08-30 22:40 ` cvs-commit at gcc dot gnu.org
2021-08-30 22:47 ` dmalcolm at gcc dot gnu.org
2021-08-31  9:50 ` rjones at redhat dot com

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).