public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/81524] Bogus or missing warnings when dereferencing pointer to deallocated stack memory
Date: Tue, 08 Feb 2022 23:01:28 +0000	[thread overview]
Message-ID: <bug-81524-4-00m0QZAdCD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-81524-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |12.0
         Resolution|---                         |FIXED
             Blocks|                            |104077

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
As far as I can see this works as requested without sanitization in GCC 12:

$ (set -x; for p in PARAM RETURN BLOCK; do for m in READ WRITE; do gcc
-DTEST_${p}_$m -S -Wall pr81524.c; done; done)
+ for p in PARAM RETURN BLOCK
+ for m in READ WRITE
+ gcc -DTEST_PARAM_READ -S -Wall pr81524.c
pr81524.c: In function ‘test_param_local’:
pr81524.c:33:7: warning: storing the address of local variable ‘local’ in ‘*pp’
[-Wdangling-pointer=]
   33 |   *pp = &local;
      |   ~~~~^~~~~~~~
pr81524.c:32:7: note: ‘local’ declared here
   32 |   int local = 1;
      |       ^~~~~
pr81524.c:32:7: note: ‘pp’ declared here
+ for m in READ WRITE
+ gcc -DTEST_PARAM_WRITE -S -Wall pr81524.c
pr81524.c: In function ‘test_param_local’:
pr81524.c:33:7: warning: storing the address of local variable ‘local’ in ‘*pp’
[-Wdangling-pointer=]
   33 |   *pp = &local;
      |   ~~~~^~~~~~~~
pr81524.c:32:7: note: ‘local’ declared here
   32 |   int local = 1;
      |       ^~~~~
pr81524.c:32:7: note: ‘pp’ declared here
+ for p in PARAM RETURN BLOCK
+ for m in READ WRITE
+ gcc -DTEST_RETURN_READ -S -Wall pr81524.c
pr81524.c: In function ‘test_return_local’:
pr81524.c:42:10: warning: function returns address of local variable
[-Wreturn-local-addr]
   42 |   return &local;
      |          ^~~~~~
+ for m in READ WRITE
+ gcc -DTEST_RETURN_WRITE -S -Wall pr81524.c
pr81524.c: In function ‘test_return_local’:
pr81524.c:42:10: warning: function returns address of local variable
[-Wreturn-local-addr]
   42 |   return &local;
      |          ^~~~~~
+ for p in PARAM RETURN BLOCK
+ for m in READ WRITE
+ gcc -DTEST_BLOCK_READ -S -Wall pr81524.c
pr81524.c: In function ‘main’:
pr81524.c:88:10: warning: using dangling pointer ‘p’ to ‘local’
[-Wdangling-pointer=]
   88 |   return *p;
      |          ^~
pr81524.c:76:9: note: ‘local’ declared here
   76 |     int local = 1;
      |         ^~~~~
pr81524.c:81:3: warning: using dangling pointer ‘p’ to ‘local’
[-Wdangling-pointer=]
   81 |   printf("%d\n", *p);
      |   ^~~~~~~~~~~~~~~~~~
pr81524.c:76:9: note: ‘local’ declared here
   76 |     int local = 1;
      |         ^~~~~
+ for m in READ WRITE
+ gcc -DTEST_BLOCK_WRITE -S -Wall pr81524.c
pr81524.c: In function ‘main’:
pr81524.c:88:10: warning: using dangling pointer ‘p’ to ‘local’
[-Wdangling-pointer=]
   88 |   return *p;
      |          ^~
pr81524.c:76:9: note: ‘local’ declared here
   76 |     int local = 1;
      |         ^~~~~
pr81524.c:84:6: warning: using dangling pointer ‘p’ to ‘local’
[-Wdangling-pointer=]
   84 |   *p = 1;
      |   ~~~^~~
pr81524.c:76:9: note: ‘local’ declared here
   76 |     int local = 1;
      |         ^~~~~


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104077
[Bug 104077] bogus/missing -Wdangling-pointer

       reply	other threads:[~2022-02-08 23:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-81524-4@http.gcc.gnu.org/bugzilla/>
2022-02-08 23:01 ` msebor at gcc dot gnu.org [this message]
2022-02-10 21:29 ` fredrik.hederstierna@securitas-direct.com
2022-02-10 23:35 ` [Bug middle-end/81524] " msebor 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-81524-4-00m0QZAdCD@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).