Bug 444264

Summary: Valgrind is not able to detect sample array bound read and write.
Product: [Developer tools] valgrind Reporter: wyy <wanglllg2200>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED NOT A BUG    
Severity: critical CC: tom
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description wyy 2021-10-23 11:00:44 UTC
SUMMARY


STEPS TO REPRODUCE
1. use the following code as a test program
  #include <iostream>
  using namespace std;
   
  void func() {
    int a[12] = {0};
    a[13] = 100;
    std::cout << "end: " << a[13] << std::endl;
  }
   
  int main() {
    func();
    return 0;
  }


2. compile the code using command:  g++ -g -O0 ./test.cpp -o ./test

3.run the valgrind with:  valgrind --tool=memcheck --leak-check=full ./test

OBSERVED RESULT
==4613== Memcheck, a memory error detector
==4613== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4613== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==4613== Command: ./test.exe
==4613== 
end: 100
==4613== 
==4613== HEAP SUMMARY:
==4613==     in use at exit: 0 bytes in 0 blocks
==4613==   total heap usage: 2 allocs, 2 frees, 73,728 bytes allocated
==4613== 
==4613== All heap blocks were freed -- no leaks are possible
==4613== 
==4613== For lists of detected and suppressed errors, rerun with: -s
==4613== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

EXPECTED RESULT
writing exceeding the bound of the array shall be detected

SOFTWARE/OS VERSIONS 
Windows: N.A.
macOS: N.A.
Linux/KDE Plasma: Ubuntu 18.04 LTS, Ubuntu 20.04 LTS
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
if you change the size of array to 10, and access array[11], the program will crash with stack smashing and the valgrind works well
Comment 1 Tom Hughes 2021-10-23 11:47:54 UTC
Place see https://valgrind.org/docs/manual/faq.html#faq.overruns for the explanation.