What's the D equivalence?
Imperatorn
johan_forsberg_86 at hotmail.com
Sat Mar 6 11:52:41 UTC 2021
On Saturday, 6 March 2021 at 11:48:37 UTC, Nick Treleaven wrote:
> On Friday, 5 March 2021 at 21:09:38 UTC, tsbockman wrote:
>> [...]
>
> Yes, and due to `ref` it can occur even when it looks like a
> null dereference should have happened:
>
> @safe:
>
> void f(ref BigFixedArr b)
> {
> // ... complex logic
> b[b.length-1] = 4; // possible memory corruption even on null
> trapping systems
> }
> void main()
> {
> BigFixedArr* p;
> // ... complex logic
> f(*p); // at least if p is accidentally null, it will crash
> here, right? nope
> }
>
> This could be fixed by checking for null in @safe code when
> dereferencing a pointer passed to a `ref` parameter. But that
> doesn't fix the unsafety of the sowChaos example (although at
> least that isn't so confusing).
To summarize, am I safe if I always null check? 🤔
More information about the Digitalmars-d
mailing list