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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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

Hello
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()
{
    f(NULL);
}



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux