Bug #4198

Saving an empty GModelSpectralTable model leads to a segmentation fault

Added by Knödlseder Jürgen almost 2 years ago. Updated almost 2 years ago.

Status:ClosedStart date:01/13/2023
Priority:NormalDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:2.1.0
Duration:

Description

>>> import gammalib
>>> spectrum=gammalib.GModelSpectralTable()
>>> spectrum.save('spectrum.fits')
Segmentation fault: 11

Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen almost 2 years ago

  • Status changed from New to Pull request
  • % Done changed from 0 to 100

The problem is easily fixed by changing the code as follows:

GFitsBinTable GModelSpectralTable::create_spec_table(void) const
{
    // Compute number of rows
    int nrows = 0;
    if (m_spectra.dim() > 0) {
        nrows = 1;
        for (int i = 0; i < m_spectra.dim()-1; ++i) {
            nrows *= m_spectra.shape()[i];
        }
    }
This results in
$ python
>>> import gammalib
>>> spectrum=gammalib.GModelSpectralTable()
>>> spectrum.save('spectrum.fits')
>>> ^D

#2 Updated by Knödlseder Jürgen almost 2 years ago

  • Status changed from Pull request to Closed

Merged into devel.

Also available in: Atom PDF