gcc warn when pointers not checked non-null before de-referencing.

Jonny Grant jg@jguk.org
Thu Jun 17 20:44:27 GMT 2021

On 16/06/2021 18:59, Segher Boessenkool wrote:
> On Wed, Jun 16, 2021 at 02:01:05PM +0100, Jonny Grant wrote:
>> I guess a separate static analyser would do it, GCC is more focused on compilation so I shouldn't ask for it to have so many features it can't support.
> -fsanitize=undefined already catches null pointer dereferences, is that
> enough for your case?
> Segher

Thank you for the suggestion, yes, I had used that before. I did just check, it's runtime checks. I had hoped for something at compile time. warning for every function that didn't check pointer for NULL before de-referencing.

$ ./null
null.c:7:5: runtime error: load of null pointer of type 'int'
Segmentation fault (core dumped)

// gcc -Wall -fsanitize=undefined -o null null.c

#include <stdio.h>

void f(int * p)
    printf("%d\n", *p);

int main()

More information about the Gcc-help mailing list