monarch_dodra:

What bothers me is that it was my understanding that the D
language standard protected me from this kind of undefined
behavior. I did make use of anything unsafe, so what gives?
Compiler not catch it but should have?

Currently the compiler doesn't track where is located the memory of dynamic array slices. In general it's hard to perform this analysis, so I think the D compiler isn't supposed to catch all such bugs.

On the other hand a certain amount of logic to statically detect simple cases like this one should be added. Maybe you want to add this as a Bugzilla enhancement request. If you have a strong C++ background you may even be able to write a patch in GitHub that implements a basic form of such static analysis.

Regarding @safe, it can't help you here. Since day 0 I've said @safe is a named wrongly, because it just refers to a narrow definition of memory safety, that doesn't include the class of bugs discussed here.

Bye,
bearophile

Reply via email to