This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/82520] New: Missing warning when stack addresses escape the current scope


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]