Currently I am using Valgrind to check memory leak and take Purify as an alternative. Valgrind can find out the access violation on an array created in heap but not in stack.
char* a = static_cast<char*>(malloc(sizeof(char) * 5));
a[7] = 'c';
printf("%c\n", a[7]);
free(a);
Valgrind points of invalid write and read in the above code, but not the following code.
char a[5] = {0};
a[7] = 'c';
printf("%c\n", a[7]);
Can Purify identify the access violation of the both blocks of code?
According to the user's guide ( ftp://ftp.software.ibm.com/software/rational/docs/v2003/purify/html/ht_m_sbr.htm ) and ( ftp://ftp.software.ibm.com/software/rational/docs/v2003/purify/html/ht_m_sbw.htm ), Purify can detect both stack boundary read and write.
However, trying your actual examples only the violation on heap data was detected also by Purify. I have only tested the latest version from IBM (7.0.1), both for Linux and Solaris.
You may want to look at -fsanitize=address for gcc 4.8 and later.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.