Is there any way to do array bounds checking in C++ compiled using g++?
-
Valgrind’s Memcheck can’t detect overflows on arrays allocated on the stack.
-
The GCC extension enabled by
-fbounds-checkingis only implemented for the C front end.
Ideally, the source code shouldn’t be modified in any way. Using std::vector, std::tr1::array or boost::array is not an option because the codebase is large and such shift would be infeasible.
There is a Valgrind tool called SGCheck (formerly known as Ptrcheck) that does check stack array bounds overrun.
The tool is still labeled experimental and it comes with several limitations. One of them is: