Ruggero Turra
Ruggero Turra

Reputation: 17680

strange segmentation violation

I have a crash, from my log:

15:21:12  1645 Wrk-0.14 | *** Break ***: segmentation violation

the stack trace is:

===========================================================
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

the function is:

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) {

the last line is the number 2375. I really don't undertand how this crash is possibile, I think I've checked everythings with the asserts. PV_z is a *std::vector<float>

Upvotes: 1

Views: 610

Answers (2)

kikeenrique
kikeenrique

Reputation: 2669

Don't discard that PV_z points to the moon, which will bypass the assert.

Upvotes: 1

timrau
timrau

Reputation: 23058

If PV_z->size() == 0, then PV_z->size()-1 underflows to UINT_MAX, and you could easily get a segmentation violation since the for-loop condition is always true.

One way to fix it:

for (unsigned int index_PV=0; !PV_z->empty() && index_PV<PV_z->size()-1;index_PV++) {
                            //^^^^^^^^^^^^^^^^^^

Upvotes: 2

Related Questions