我有一个崩溃,从我的日志:
15:21:12 1645 Wrk-0.14 | *** Break ***: segmentation violation
堆栈跟踪为:
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
...
#4 <signal handler called>
#5 0x00002b5eeef98865 in HiggsSelector::RejectBadJet (this=0x1de241a0,
index_jet=0, index_leading=0, index_subleading=1) at HiggsSelector.C:2375
函数为:
bool HiggsSelector::RejectBadJet(int index_jet, int index_leading, int index_subleading) const
{
assert(index_jet >= 0);
assert(index_leading >= 0);
assert(index_subleading >= 0);
assert(PV_z);
int index_PV_ID_chosen=0; //<-----in your header
double DiPhoton_zcommon=z_common_corrected(index_leading,index_subleading,false);
float minimal_distance=9999;
for (unsigned int index_PV=0;index_PV<PV_z->size()-1;index_PV++) {
if ( fabs((*PV_z)[index_PV]-DiPhoton_zcommon)<minimal_distance) {
最后一行是数字 2375。我真的不明白这次崩溃的可能性,我想我已经用assert
检查了一切。 PV_z
是一个*std::vector<float>
如果PV_z->size() == 0
,则PV_z->size()-1
下溢到UINT_MAX
,并且由于 for 循环条件始终为真,您很容易获得分段冲突。
一种解决方法:
for (unsigned int index_PV=0; !PV_z->empty() && index_PV<PV_z->size()-1;index_PV++) {
//^^^^^^^^^^^^^^^^^^
不要丢弃指向月球的PV_z,这将绕过断言。