IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2006, 12:43:26 PM (20 years ago)
Author:
Paul Price
Message:

Adding NULL checks at function start, to provide some robustness, following SEGVs when CELL.TRIMSEC specified incorrectly in the camera format configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPA.c

    r7173 r7274  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-05-23 01:09:48 $
     14*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-06-01 22:43:26 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    136136void pmCellFreeReadouts(pmCell *cell)
    137137{
     138    PS_ASSERT_PTR_NON_NULL(cell,);
     139
    138140    //
    139141    // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
     
    156158void pmChipFreeCells(pmChip *chip)
    157159{
     160    PS_ASSERT_PTR_NON_NULL(chip,);
     161
    158162    //
    159163    // Set the parent to NULL in all chip->cells before psFree(chip->cells)
     
    175179void pmCellFreeData(pmCell *cell)
    176180{
     181    PS_ASSERT_PTR_NON_NULL(cell,);
     182
    177183    pmCellFreeReadouts(cell);
    178184    if (cell->hdu) {
     
    184190void pmChipFreeData(pmChip *chip)
    185191{
     192    PS_ASSERT_PTR_NON_NULL(chip,);
     193
    186194    for (int i = 0; i < chip->cells->n; i++) {
    187195        pmCellFreeData(chip->cells->data[i]);
     
    195203void pmFPAFreeData(pmFPA *fpa)
    196204{
     205    PS_ASSERT_PTR_NON_NULL(fpa,);
     206
    197207    for (int i = 0; i < fpa->chips->n; i++) {
    198208        pmChipFreeData(fpa->chips->data[i]);
     
    206216pmReadout *pmReadoutAlloc(pmCell *cell)
    207217{
    208     pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
     218    pmReadout *tmpReadout = (pmReadout *)psAlloc(sizeof(pmReadout));
    209219    psMemSetDeallocator(tmpReadout, (psFreeFunc) readoutFree);
    210220
     
    215225    tmpReadout->analysis = psMetadataAlloc();
    216226    tmpReadout->parent = cell;
    217     if (cell != NULL) {
     227    if (cell) {
    218228        cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
    219229    }
     
    241251    tmpCell->readouts = psArrayAlloc(0);
    242252    tmpCell->parent = chip;
    243     if (chip != NULL) {
     253    if (chip) {
    244254        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
    245255    }
     
    256266    pmConceptsBlankCell(tmpCell);
    257267
    258     return(tmpCell);
     268    return tmpCell;
    259269}
    260270
     
    263273    const char *name)
    264274{
    265     pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
     275    pmChip *tmpChip = (pmChip*)psAlloc(sizeof(pmChip));
    266276    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
    267277
    268     # if FPA_ASTROM
     278    #if FPA_ASTROM
    269279
    270280    tmpChip->col0 = 0;
    271 tmpChip->row0 = 0;
    272 tmpChip->toFPA = NULL;
    273 tmpChip->fromFPA = NULL;
    274 # endif
    275 
    276 tmpChip->analysis = psMetadataAlloc();
     281    tmpChip->row0 = 0;
     282    tmpChip->toFPA = NULL;
     283    tmpChip->fromFPA = NULL;
     284    # endif
     285
     286    tmpChip->analysis = psMetadataAlloc();
    277287    tmpChip->cells = psArrayAlloc(0);
    278288    tmpChip->parent = fpa;
    279     if (fpa != NULL) {
    280         psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
     289    if (fpa) {
     290        psArrayAdd(fpa->chips, 1, (psPtr)tmpChip);
    281291    }
    282292    tmpChip->hdu = NULL;
     
    292302    }
    293303    pmConceptsBlankChip(tmpChip);
    294     return(tmpChip);
     304    return tmpChip;
    295305}
    296306
     
    300310    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
    301311
    302     # if FPA_ASTROM
     312    #if FPA_ASTROM
    303313
    304314    tmpFPA->fromTangentPlane = NULL;
    305 tmpFPA->toTangentPlane = NULL;
    306 tmpFPA->projection = NULL;
    307 # endif
    308 
    309 tmpFPA->analysis = NULL;
    310 tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
     315    tmpFPA->toTangentPlane = NULL;
     316    tmpFPA->projection = NULL;
     317    # endif
     318
     319    tmpFPA->analysis = NULL;
     320    tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
    311321    tmpFPA->chips = psArrayAlloc(0);
    312322    tmpFPA->hdu = NULL;
     
    316326    pmConceptsBlankFPA(tmpFPA);
    317327
    318     return(tmpFPA);
    319 }
    320 
    321 static psBool cellCheckParents(pmCell *cell)
    322 {
    323     if (!cell) {
    324         return(true);
    325     }
    326     psBool flag = true;
    327 
    328     for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
     328    return tmpFPA;
     329}
     330
     331static bool cellCheckParents(pmCell *cell)
     332{
     333    PS_ASSERT_PTR_NON_NULL(cell, true);
     334
     335    bool flag = true;
     336    for (long i = 0; i < cell->readouts->n ; i++) {
    329337        pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
    330         PS_ASSERT_PTR_NON_NULL(tmpReadout, false);
     338        if (!tmpReadout) {
     339            continue;
     340        }
    331341        if (tmpReadout->parent != cell) {
    332342            tmpReadout->parent = cell;
     
    334344        }
    335345    }
    336     return(flag);
    337 }
    338 
    339 static psBool chipCheckParents(pmChip *chip)
    340 {
    341     if (!chip) {
    342         return(true);
    343     }
    344     psBool flag = true;
    345 
    346     for (psS32 i = 0 ; i < chip->cells->n ; i++) {
     346    return flag;
     347}
     348
     349static bool chipCheckParents(pmChip *chip)
     350{
     351    PS_ASSERT_PTR_NON_NULL(chip, true);
     352
     353    bool flag = true;
     354    for (long i = 0; i < chip->cells->n ; i++) {
    347355        pmCell *tmpCell = (pmCell *) chip->cells->data[i];
    348         PS_ASSERT_PTR_NON_NULL(tmpCell, false);
     356        if (!tmpCell) {
     357            continue;
     358        }
    349359        if (tmpCell->parent != chip) {
    350360            tmpCell->parent = chip;
     
    354364        flag &= cellCheckParents(tmpCell);
    355365    }
    356     return(flag);
     366    return flag;
    357367}
    358368
    359369psBool pmFPACheckParents(pmFPA *fpa)
    360370{
    361     if (!fpa) {
    362         return(true);
    363     }
    364     psBool flag = true;
    365 
    366     for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
     371    PS_ASSERT_PTR_NON_NULL(fpa, true);
     372
     373    bool flag = true;
     374    for (long i = 0; i < fpa->chips->n ; i++) {
    367375        pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
    368         PS_ASSERT_PTR_NON_NULL(tmpChip, false);
     376        if (!tmpChip) {
     377            continue;
     378        }
    369379        if (tmpChip->parent != fpa) {
    370380            tmpChip->parent = fpa;
     
    374384        flag &= chipCheckParents(tmpChip);
    375385    }
    376     return(flag);
     386    return flag;
    377387}
    378388
    379389/** functions to turn on/off the file_exists flag **/
    380 bool pmFPASetFileStatus (pmFPA *fpa, bool status)
    381 {
     390bool pmFPASetFileStatus(pmFPA *fpa, bool status)
     391{
     392    PS_ASSERT_PTR_NON_NULL(fpa, false);
    382393
    383394    for (int i = 0; i < fpa->chips->n; i++) {
     
    388399}
    389400
    390 bool pmChipSetFileStatus (pmChip *chip, bool status)
    391 {
     401bool pmChipSetFileStatus pmChip *chip, bool status)
     402{
     403    PS_ASSERT_PTR_NON_NULL(chip, false);
    392404
    393405    chip->file_exists = status;
     
    399411}
    400412
    401 bool pmCellSetFileStatus (pmCell *cell, bool status)
    402 {
     413bool pmCellSetFileStatus(pmCell *cell, bool status)
     414{
     415    PS_ASSERT_PTR_NON_NULL(cell, false);
    403416
    404417    cell->file_exists = status;
     
    411424
    412425/** functions to turn on/off the data_exists flag **/
    413 bool pmFPASetDataStatus (pmFPA *fpa, bool status)
    414 {
     426bool pmFPASetDataStatus(pmFPA *fpa, bool status)
     427{
     428    PS_ASSERT_PTR_NON_NULL(fpa, false);
    415429
    416430    for (int i = 0; i < fpa->chips->n; i++) {
     
    421435}
    422436
    423 bool pmChipSetDataStatus (pmChip *chip, bool status)
    424 {
     437bool pmChipSetDataStatus(pmChip *chip, bool status)
     438{
     439    PS_ASSERT_PTR_NON_NULL(chip, false);
    425440
    426441    chip->data_exists = status;
     
    434449bool pmCellSetDataStatus (pmCell *cell, bool status)
    435450{
     451    PS_ASSERT_PTR_NON_NULL(cell, false);
    436452
    437453    cell->data_exists = status;
     
    507523bool pmChipSelectCell(pmChip *chip, int cellNum, bool exclusive)
    508524{
    509     assert(chip);
     525    PS_ASSERT_PTR_NON_NULL(chip, false);
    510526
    511527    psArray *cells = chip->cells;       // Component cells
     
    548564    int chipNum)
    549565{
    550     PS_ASSERT_PTR_NON_NULL(fpa, false);
     566    PS_ASSERT_PTR_NON_NULL(fpa, -1);
    551567
    552568    psArray *chips = fpa->chips;        // Component chips
     
    580596                     )
    581597{
    582     assert(chip);
     598    PS_ASSERT_PTR_NON_NULL(chip, -1);
    583599
    584600    psArray *cells = chip->cells;       // The component cells
Note: See TracChangeset for help on using the changeset viewer.