a short null dereference story
Basile B.
b2.temp at gmx.com
Mon Dec 8 05:46:08 UTC 2025
On Monday, 8 December 2025 at 02:58:48 UTC, Walter Bright wrote:
> On 12/5/2025 12:58 PM, Basile B. wrote:
>> So for D the equivalent would be to generate a check on each
>> DotVarExp.
>
> ```d
> struct S { int a; }
>
> int main()
> {
> S* s = null;
> return s.a;
> }
> ```
>
> compile:
>
> [...]
>
> Program received signal SIGSEGV, Segmentation fault.
> D main () at ./test.d:8
> 8 return s.a;
Yes but the code instrumentation approach gives the opportunity
to fix the invalid read without running in the debugger. Also
note that the runtime error indicates the column. GDB is not that
precise (DWARF attrib DW_AT_decl_column is never used), so for
`x.s.a` you have to evaluate `x` then `s` to be sure.
More information about the Digitalmars-d
mailing list