This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/82520] New: Missing warning when stack addresses escape the current scope
- From: "ajax at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 11 Oct 2017 16:52:57 +0000
- Subject: [Bug c/82520] New: Missing warning when stack addresses escape the current scope
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82520
Bug ID: 82520
Summary: Missing warning when stack addresses escape the
current scope
Product: gcc
Version: 7.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ajax at redhat dot com
Target Milestone: ---
Testcase:
-----
#include <malloc.h>
struct foo { void *v; };
struct foo *bar(void)
{
int a[10];
struct foo *ret = malloc(sizeof(struct foo));
ret->v = &a;
return ret;
}
-----
The address of 'a' is just somewhere on the stack. There might be rare cases
where you'd want to do this, but usually this would be a bug.
Bug 63181 is perhaps a C++ variation of the same kind of problem, but clang
doesn't warn for this one.