Re: Dereferencing a null pointer to an array, then converting to pointer to first element

Basile Starynkevitch <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
On Tue, 2025-11-18 at 10:16 +0100, Alejandro Colomar via Gcc-help wrote:
> Hi!
> 
> The wording of the ISO C standard seems to say that the following
> program has undefined behavior:
> 
> 	alx@devuan:~/tmp$ cat null.c 
> 	#include <stddef.h>
> 
> 	int
> 	main(void)
> 	{
> 		int  (*null)[42] = NULL;
> 		int  *p = *null;
> 	}

You could try using frama-c.com (an open source static C analyzer). I believe it would catch the error.

However, catching such bugs is in general impossible. See also the https://en.wikipedia.org/wiki/Coccinelle_(software)

regards
-- 

Basile STARYNKEVITCH                    basile AT starynkevitch DOT net
8 rue de la Faïencerie                       http://starynkevitch.net/Basile/  
92340 Bourg-la-Reine                         https://github.com/bstarynk
France                                https://github.com/RefPerSys/RefPerSys
                  https://orcid.org/0000-0003-0908-5250
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.