null pointer dereference detection in DMD
Iain Buclaw
ibuclaw at gdcproject.org
Sat Jan 11 09:51:23 UTC 2025
On Saturday, 11 January 2025 at 02:01:50 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> On 11/01/2025 2:43 PM, Walter Bright wrote:
>> Curiously, compiling it with `gcc -O3` does not detect it.
>> ImportC doesn't detect it, either, a choice made because some
>> C code uses such a construct as a way to drop into the
>> debugger.
>
> Yeah you didn't turn the warning on.
[...snip...]
> flags: ``-Wnull-dereference -O``
>
[...snip...]
> https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
>
Ergo, gdc also warns about this with the same flags.
```
$ gdc nullptrdect.d -O -Wnull-dereference
nullptrdect.d: In function ‘D main’:
nullptrdect.d:3:10: warning: null pointer dereference
[-Wnull-dereference]
3 | *ptr = 3;
| ^
```
More information about the Digitalmars-d
mailing list