From: Martin Sebor <msebor@gmail.com>
To: Jonny Grant <jg@jguk.org>, gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: gcc warn when pointers not checked non-null before de-referencing.
Date: Mon, 14 Jun 2021 09:19:09 -0600 [thread overview]
Message-ID: <d5d5ca9d-7d3f-1500-fb3c-4676d4e0778a@gmail.com> (raw)
In-Reply-To: <0a9ccbb7-135a-b342-e5cb-35b7c6a44a00@jguk.org>
On 6/13/21 4:30 PM, Jonny Grant wrote:
> Hello
>
> This isn't real code, just an example to show.
>
> I've tried with: -Wall -Wextra -O2 and some other warnings, but couldn't get this to generate a warning that *g was possibly de-referenced. May I ask, does GCC have a way to get warnings when pointers are not checked?
> I had a look but -Wnull-dereference didn't help.
The pointer test is eliminated before -Wnull-dereference runs so it
can't do anything in this case. -fno-delete-null-pointer-checks
disables the optimization and retains the test so -Wnull-dereference
could in theory detect it but it isn't designed to do it. But if
it did, I suspect it would be quite noisy as a result of other
transformations like inlining and constant propagation. So making
it work with an acceptable S/R ratio would take more work than just
enhancing -Wnull-dereference.
Martin
>
> #include <stdlib.h>
>
> #include <cstddef>
> void f(int * g)
> {
> *g = 1;
>
> if(NULL == g)
> {
> exit(1);
> }
> }
>
> Best regards Jonny
>
prev parent reply other threads:[~2021-06-14 15:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-13 22:30 Jonny Grant
2021-06-14 5:15 ` Xi Ruoyao
2021-06-16 13:01 ` Jonny Grant
2021-06-16 13:36 ` Xi Ruoyao
2021-07-03 15:36 ` Jonny Grant
2021-07-06 15:39 ` Xi Ruoyao
2021-07-19 18:20 ` Jonny Grant
2021-06-16 17:59 ` Segher Boessenkool
2021-06-17 20:44 ` Jonny Grant
2021-06-18 4:16 ` Xi Ruoyao
2021-07-03 14:14 ` Jonny Grant
2021-07-03 16:22 ` Segher Boessenkool
2021-07-06 10:33 ` Jonny Grant
2021-06-18 8:38 ` Liu Hao
2021-06-18 14:53 ` Segher Boessenkool
2021-06-14 15:19 ` Martin Sebor [this message]
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=d5d5ca9d-7d3f-1500-fb3c-4676d4e0778a@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=jg@jguk.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).