c++ - assert(pointer) 引发分段违规

标签 c++ crash segmentation-fault

在检查指针是否为 0 时,我遇到了这个烦人的段错误。这是有问题的代码:

bool egammaMVACalib::checkTree()
{
   // Not a TChain
   cout << "a" << endl;
   assert(m_tree);      // crash on line 751 (this one)
   cout << "B" << endl;

m_treeegammaMVACalib 类型的数据成员 TTree* 所以我真的不明白为什么 assert(m_tree ) 会引发分段冲突。这是带有堆栈跟踪的输出

a
19:07:25 30574 Wrk-0.9 | *** Break ***: segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x000000361869a4d5 in waitpid () from /lib64/libc.so.6
#1  0x000000361863c481 in do_system () from /lib64/libc.so.6
#2  0x00002ac5099cb322 in TUnixSystem::StackTrace() ()
    from /usr/local/proof/root/lib/libCore.so
#3  0x00002ac5099c7fea in TUnixSystem::DispatchSignals(ESignals) ()
    from /usr/local/proof/root/lib/libCore.so
#4  <signal handler called>
#5  egammaMVACalib::checkTree (this=0x0) at ../Root/egammaMVACalib.cxx:751
#6  0x00002ac5117e5563 in egammaMVACalib::LoadVariables (this=0x1, index=0)
    at ../Root/egammaMVACalib.cxx:492

最佳答案

如果您查看第 5 帧,您的 this 指针为空。这意味着问题从那里开始。断言处的段错误仅仅是对它的重复!

关于c++ - assert(pointer) 引发分段违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555872/

相关文章:

c++ - 带有指向参数的指针的基本函数重载给出错误

c++ - 重载 << 运算符导致无输出

Mac 上的 C++ 分析

python - C++ Python 模块在 Blender 中崩溃,但在 Python 控制台中没有

c - ARM交叉编译ZeroMQ zstr_rcv()给出段错误

c++ - x86 和 x86_64 中 float 和 double 的性能差异

ios - Xcode 6 - 在设备上运行应用程序崩溃

java - 使用 Arrays.fill 时崩溃

c++ - C++程序编译,运行但崩溃(无错误消息)

c - C中的许多TQLI实现是否有错误?