public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109550] New: warning: "p" may be used uninitialized
@ 2023-04-19  6:58 f.heckenbach@fh-soft.de
  2023-04-19  8:03 ` [Bug c/109550] " rguenth at gcc dot gnu.org
  2023-04-19  8:51 ` f.heckenbach@fh-soft.de
  0 siblings, 2 replies; 3+ messages in thread
From: f.heckenbach@fh-soft.de @ 2023-04-19  6:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109550
           Summary: warning: "p" may be used uninitialized
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.c
#include <stdlib.h>

int f (char const *p);

void a (void)
{
  char const *p = alloca (1);
  f (p);
}
% gcc -c -Wall test.c
test.c: In function "a":
test.c:8:3: warning: "p" may be used uninitialized [-Wmaybe-uninitialized]
    8 |   f (p);
      |   ^~~~~
test.c:3:5: note: by argument 1 of type "const char *" to "f" declared here
    3 | int f (char const *p);
      |     ^

It also happens with "malloc" instead of "alloca", but not with a normal
function.

The warning disappears when removing "const" in both places.

Ironically, when trying to work around the warning, I noticed that wrapping
alloca in another function gets rid of the warning. However, that would
actually be wrong (dangling pointer).

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

end of thread, other threads:[~2023-04-19  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19  6:58 [Bug c/109550] New: warning: "p" may be used uninitialized f.heckenbach@fh-soft.de
2023-04-19  8:03 ` [Bug c/109550] " rguenth at gcc dot gnu.org
2023-04-19  8:51 ` f.heckenbach@fh-soft.de

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