|
From: Igmar P. <mai...@jd...> - 2004-12-23 15:53:54
|
> //------- overflow.cc -----------------------------------
> // g++ -o overflow overflow.cc
> //
> #include <iostream>
> using namespace std;
> int main (int argc, char *argv[])
> {
> int array1[10] = {0}; // initialize to 0
> int array2[10] = {0}; // initialize to 0
> int array3[10] = {0}; // initialize to 0
>
> // Bad!: Fill the 10 element array with 20 elements
> for (int ind=0; ind<20; ++ind) {
> array2[ind] = ind;
> }
As already said : Valgrind can't detect these. There is a GCC patch
(boundchecking) that adds redzones to stack allocated variables so that it
will detect overflows. It's unlikely that valgrind will support this some
day due to the way stack allocations works. More details are in the FAQ.
Igmar
|