Bug #1850

ctbin fails with segmentation fault

Added by Mayer Michael about 8 years ago. Updated over 7 years ago.

Status:ClosedStart date:08/29/2016
Priority:HighDue date:
Assigned To:Mayer Michael% Done:

100%

Category:-
Target version:1.2.0
Duration:

Description

I realised that in the current version of ctbin, we get a segmentation fault when running on an observation container with different energy thresholds.
The problem occurs in line ctbin.cpp:.526, where we query for the usage of the energy bin, depending on the event energy.
The variable iebin is not checked before checking usage[iebin]. However, in case the cube is only a subset of the complete energy range, an event energy may be outside the cube energy range. Consequently the line before

int iebin = m_ebounds.index(event->energy());

can result in iebin=-1. Therefore, we need to add a check and replace the if statement by:
if (iebin == -1 || !usage[iebin]) {
    num_outside_ebds++;
    continue;
}

Note: we need to make sure that the first part of the condition is evaluated first. I recall we had some issues with the order how c++ executes the || statements.


Recurrence

No recurrence.

History

#1 Updated by Mayer Michael about 8 years ago

This problem can be reproduced by changing the energy range of one of the ctbin unit tests to e.g. 0.5-20 TeV instead of using 0.1-100 TeV throughout the tests.

#2 Updated by Mayer Michael about 8 years ago

  • Status changed from New to Pull request
  • Assigned To changed from Knödlseder Jürgen to Mayer Michael

I fixed the problem using the above solution. I also added an additional unit test for ctbin with a different energy range (which would have failed before).

To avoid merging conflicts, I added the changes also on branch 1846-use-ctobservation-base-class (which is the same as for #1846).

#3 Updated by Knödlseder Jürgen about 8 years ago

  • Status changed from Pull request to Closed

Merged into devel.

#4 Updated by Knödlseder Jürgen over 7 years ago

  • % Done changed from 0 to 100

Also available in: Atom PDF