I'd like to allocate an array and set it up such that the pages before and after it are protected by the memory management unit, so an attempt to run over the bounds of the array will be automatically caught; and then catch it in order to handle the error in a controlled fashion.
I doubt there will be a portable solution, but what's the best platform specific method using Microsoft C on Windows and GCC on Linux respectively?
Actually, there is a portable way to detect memory allocation overruns in software. Dmalloc provides fencepost overwrite detection
http://dmalloc.com/docs/latest/online/dmalloc_17.html#SEC22