Bad array indexing is considered deadly

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Wed May 31 17:11:10 PDT 2017


On 01.06.2017 01:55, Moritz Maxeiner wrote:
> On Wednesday, 31 May 2017 at 23:40:00 UTC, Timon Gehr wrote:
>>>
>>> In the context of the conversation, and error has already occurred 
>>> and the all cases was referring to all the cases that lead to the error.
>> Bounds checks have /no business at all/ trying to handle preexisting 
>> memory corruption,
> 
> Sure, because the program is in an undefined state by that point.

What does that even mean? Everything is perfectly well-defined here:

void main(){
     auto a = new int[](2);
     a[2] = 3;
}

> There is only termination.
> ...


Termination of what? How on earth do you determine that the scope of 
this "undefined state" is the program, not the machine, or the world? 
I.e., why terminate the program, but not shut down the machine or nuke 
the planet?

Scoping really ought to be up to the programmer as it greatly depends on 
the actual circumstances. Program termination is the only reasonable 
default behaviour, but it is not the only reasonable behaviour.


More information about the Digitalmars-d mailing list