Bad array indexing is considered deadly

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed May 31 06:04:52 PDT 2017


I have discovered an annoyance in using vibe.d instead of another web 
framework. Simple errors in indexing crash the entire application.

For example:

int[3] arr;
arr[3] = 5;

Compare this to, let's say, a malformed unicode string (exception), 
malformed JSON data (exception), file not found (exception), etc.

Technically this is a programming error, and a bug. But memory hasn't 
actually been corrupted. The system properly stopped me from corrupting 
memory. But my reward is that even though this fiber threw an Error, and 
I get an error message in the log showing me the bug, the web server 
itself is now out of commission. No other pages can be served. This is 
like the equivalent of having a guard rail on a road not only stop you 
from going off the cliff but proactively disable your car afterwards to 
prevent you from more harm.

This seems like a large penalty for "almost" corrupting memory. No other 
web framework I've used crashes the entire web server for such a simple 
programming error. And vibe.d has no choice. There is no guarantee the 
stack is properly unwound, so it has to accept the characterization of 
this is a program-ending error by the D runtime.

I am considering writing a set of array wrappers that throw exceptions 
when trying to access out of bounds elements. This comes with its own 
set of problems, but at least the web server should continue to run.

What are your thoughts? Have you run into this? If so, how did you solve it?

-Steve


More information about the Digitalmars-d mailing list