关于简单代码的Mudflap段错误

时间:2014-04-21 09:10:23

标签: c++ segmentation-fault

我正在调试我的作业,我遇到了这个简单代码的情况:

/* test.cpp */

#include <cstring> 
#include <iostream>
using namespace std;

int main(){

  char * x;
  x = new char [6];
  strcpy(x, "hello");

  cout << "<" << x << ">" << endl;

  delete [] x;
}

我在终端编译它并设置mudflap选项:

$ g++ -fmudflap -fmudflapir -lmudflap -g test.cpp
$ export MUDFLAP_OPTIONS='-viol-segv -print-leaks'

当我运行它时,输出是:

<hello>
*******
mudflap violation 1 (unregister): time=1398070624.859727 ptr=0x1bcba00 size=0
pc=0x7f8de0cbde08
Nearby object 1: checked region begins 299B after and ends 299B after
mudflap dead object 0x1bcb930: name=`malloc region'
bounds=[0x1bcb8d0,0x1bcb8d5] size=6 area=heap check=0r/1w liveness=1
alloc time=1398070624.859316 pc=0x7f8de0cbd778
  /usr/lib/x86_64-linux-gnu/libmudflap.so.0(__mf_register+0x18) [0x7f8de0cbd778]
  /usr/lib/x86_64-linux-gnu/libmudflap.so.0(__real_malloc+0xc0) [0x7f8de0cbe280]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x1d) [0x7f8de0a0ef4d]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znam+0x9) [0x7f8de0a0f049]
dealloc time=1398070624.859615 pc=0x7f8de0cbde08
  /usr/lib/x86_64-linux-gnu/libmudflap.so.0(__mf_unregister+0x18) [0x7f8de0cbde08]
  /usr/lib/x86_64-linux-gnu/libmudflap.so.0(free+0x8a) [0x7f8de0cbe74a]
  ./a.out(main+0x72) [0x400cbf]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f8de0609de5]
number of nearby objects: 1
Unauthorized access to memory (SIGSEGV) (core dumped [memory image saved])

我无法找出问题所在。

0 个答案:

没有答案