Commit ced3feb63124b513cd3075cfb2a4baa8ca1db3de

Authored by knodlseder
1 parent 50927443

initialise column pointers with NULL to allow for clean destruction

Showing 1 changed file with 8 additions and 4 deletions
src/fits/GFitsTable.cpp
... ... @@ -483,9 +483,13 @@ void GFitsTable::open(__fitsfile* fptr)
483 483 if (status != 0)
484 484 throw GException::fits_error(G_OPEN, status);
485 485  
486   - // Allocate memory for column pointers
  486 + // Allocate and initialise memory for column pointers. Note that this
  487 + // initialisation is needed to allow for a clean free_members() call
  488 + // in case of any exception.
487 489 if (m_columns != NULL) delete [] m_columns;
488 490 m_columns = new GFitsTableCol*[m_cols];
  491 + for (int i = 0; i < m_cols; ++i)
  492 + m_columns[i] = NULL;
489 493  
490 494 // Get table column information
491 495 int typecode = 0;
... ... @@ -513,7 +517,7 @@ void GFitsTable::open(__fitsfile* fptr)
513 517 sprintf(keyname, "TZERO%d", i+1);
514 518 status = __ffgky(&m_fitsfile, __TULONG, keyname, &offset, NULL, &status);
515 519 if (status == 0) {
516   - if (typecode == __TSHORT && offset == 32678u)
  520 + if (typecode == __TSHORT && offset == 32768u)
517 521 typecode = __TUSHORT;
518 522 else if (typecode == __TLONG && offset == 2147483648u)
519 523 typecode = __TULONG;
... ... @@ -521,8 +525,8 @@ void GFitsTable::open(__fitsfile* fptr)
521 525 typecode = __TUINT;
522 526 else {
523 527 std::ostringstream message;
524   - message << "Column " << value << " has typecode " << typecode
525   - << " and unexpected associated TZERO=" << offset;
  528 + message << ", but column " << value << " has typecode " << typecode
  529 + << " and unexpected associated TZERO=" << offset << ".";
526 530 throw GException::fits_error(G_OPEN, 0, message.str());
527 531 }
528 532 }
... ...