From: R O <mu...@ya...> - 2004-12-23 08:54:54
|
Hello, I am trying to find a subtle bug that overwrites memory but which is not detectable with valgrind. I am using ROOT based code (http/root.cern.ch/) and when I ran under valgrind with --tool=mememcheck, valgrind can not detect the error that causes memory corruption. Part of the problem could be that root has its own interpreter. My question is: is it possible to detect with valgrind memory overwrites where a program writes to a memory space pass allocated space of a particular array but while still writing to the memory that was allocated somewhere else in the program? For example, valgrind can not detect the memory overwrite in the example below, which is likely to be what is happening in my case. Thank you very much, Rust //------- 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; } // Print out the arrays for (int ind=0; ind<10; ++ind) { cout << "array1["<<ind<<"] = " << array1[ind] << endl; } for (int ind=0; ind<10; ++ind) { cout << "array2["<<ind<<"] = " << array2[ind] << endl; } for (int ind=0; ind<10; ++ind) { cout << "array3["<<ind<<"] = " << array3[ind] << endl; } return 0; } // end of main() //------------------------------------------------------- __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |