Valgrind的不承认写无效

问题描述 投票:0回答:1

Valgrind的不检测内存错误。

我使用的valgrind 3.11,ubuntu下GCC 5.4.0,并有一个不正确的代码在我的程序,如样本。

我分析了这个程序,使用的valgrind。但是的valgrind没有任何错误报告。

  #include <string.h>
   int main(){
     int a[3];
     memcpy(a,"aaabbbcccdddeeefffggghhh", 24);
     return 0;
   }

这有什么错的valgrind?

c++ ubuntu-16.04 valgrind
1个回答
2
投票

Valgrind的不知道,而不是它的大小,然后,当你在堆栈中留下无法检测错误


为了比较,具有:

#include <string.h>
int main(){
  int * a = new int[3];
  memcpy(a,"aaabbbcccdddeeefffggghhh", 24);
  return 0;
}

因为它知道分配的内存块的大小的valgrind可以检测到错误:

pi@raspberrypi:/tmp $ valgrind ./a.out
==16164== Memcheck, a memory error detector
==16164== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16164== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==16164== Command: ./a.out
==16164== 
==16164== Invalid write of size 8
==16164==    at 0x4865F44: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==16164==  Address 0x4bc9f60 is 8 bytes inside a block of size 12 alloc'd
==16164==    at 0x48485F0: operator new[](unsigned int) (vg_replace_malloc.c:417)
==16164==    by 0x105A7: main (v.cc:3)
==16164== 
==16164== Invalid write of size 8
==16164==    at 0x4865F54: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==16164==  Address 0x4bc9f68 is 4 bytes after a block of size 12 alloc'd
==16164==    at 0x48485F0: operator new[](unsigned int) (vg_replace_malloc.c:417)
==16164==    by 0x105A7: main (v.cc:3)
==16164== 
==16164== 
==16164== HEAP SUMMARY:
==16164==     in use at exit: 12 bytes in 1 blocks
==16164==   total heap usage: 2 allocs, 1 frees, 20,236 bytes allocated
==16164== 
==16164== LEAK SUMMARY:
==16164==    definitely lost: 12 bytes in 1 blocks
==16164==    indirectly lost: 0 bytes in 0 blocks
==16164==      possibly lost: 0 bytes in 0 blocks
==16164==    still reachable: 0 bytes in 0 blocks
==16164==         suppressed: 0 bytes in 0 blocks
==16164== Rerun with --leak-check=full to see details of leaked memory
==16164== 
==16164== For counts of detected and suppressed errors, rerun with: -v
==16164== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 3)
© www.soinside.com 2019 - 2024. All rights reserved.