IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2008, 2:47:49 PM (18 years ago)
Author:
Paul Price
Message:

Reworking to avoid "'value' may be used uninitialized in this function".
Plugging memory leak.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats/src/ppStatsFromMetadataStats.c

    r19955 r19965  
    22
    33// calculate the stats for the non-constant entries (already calculated)
    4 bool ppStatsFromMetadataStats (psArray *entries) {
    5 
    6     double value;
    7     psStats *stats = NULL;
     4bool ppStatsFromMetadataStats(psArray *entries) {
    85
    96    for (int i = 0; i < entries->n; i++) {
    10         ppStatsEntry *entry = entries->data[i];
     7        ppStatsEntry *entry = entries->data[i];
    118
    12         if (!strcasecmp (entry->statistic, "constant")) continue;
    13        
    14         // XXX skip or warn on missing stats?
    15         if (!entry->vector) continue;
     9        if (!strcasecmp(entry->statistic, "constant")) {
     10            continue;
     11        }
    1612
    17         psStatsOptions option;
    18         if (!strcasecmp (entry->statistic, "RMS")) {
    19             option = psStatsOptionFromString ("ROBUST_MEDIAN");
    20             goto got_stats;
    21         }
    22         if (!strcasecmp (entry->statistic, "SUM")) {
    23             option = psStatsOptionFromString ("SAMPLE_MEAN");
    24             goto got_stats;
    25         }
    26         if (!strcasecmp (entry->statistic, "UQ")) {
    27             option = psStatsOptionFromString ("ROBUST_QUARTILE");
    28             goto got_stats;
    29         }
    30         if (!strcasecmp (entry->statistic, "LQ")) {
    31             option = psStatsOptionFromString ("ROBUST_QUARTILE");
    32             goto got_stats;
    33         }
     13        // XXX skip or warn on missing stats?
     14        if (!entry->vector) {
     15            continue;
     16        }
    3417
    35         option = psStatsOptionFromString (entry->statistic);
    36        
    37     got_stats:
    38         stats = psStatsAlloc (option);
     18        psStatsOptions option;
     19        if (!strcasecmp (entry->statistic, "RMS")) {
     20            option = psStatsOptionFromString ("ROBUST_MEDIAN");
     21        } else if (!strcasecmp (entry->statistic, "SUM")) {
     22            option = psStatsOptionFromString ("SAMPLE_MEAN");
     23        } else if (!strcasecmp (entry->statistic, "UQ")) {
     24            option = psStatsOptionFromString ("ROBUST_QUARTILE");
     25        } else if (!strcasecmp (entry->statistic, "LQ")) {
     26            option = psStatsOptionFromString ("ROBUST_QUARTILE");
     27        } else {
     28            option = psStatsOptionFromString (entry->statistic);
     29        }
    3930
    40         psVectorStats (stats, entry->vector, NULL, NULL, 0);
     31        psStats *stats = psStatsAlloc(option);
    4132
    42         if (!strcasecmp (entry->statistic, "RMS")) {
    43             value = sqrt(value);
    44             goto got_value;
    45         }
    46         if (!strcasecmp (entry->statistic, "SUM")) {
    47             value = stats->sampleMean * entry->vector->n;
    48             goto got_value;
    49         }
    50         if (!strcasecmp (entry->statistic, "UQ")) {
    51             value = stats->robustUQ;
    52             goto got_value;
    53         }
    54         if (!strcasecmp (entry->statistic, "LQ")) {
    55             value = stats->robustLQ;
    56             goto got_value;
    57         }
    58         value = psStatsGetValue (stats, option);
     33        psVectorStats(stats, entry->vector, NULL, NULL, 0);
    5934
    60     got_value:
    61         entry->value = psMetadataItemAllocF32 (entry->keyword, entry->statistic, value);
     35        double value;
     36        if (!strcasecmp (entry->statistic, "RMS")) {
     37            value = sqrt(value);
     38        } else if (!strcasecmp (entry->statistic, "SUM")) {
     39            value = stats->sampleMean * entry->vector->n;
     40        } else if (!strcasecmp (entry->statistic, "UQ")) {
     41            value = stats->robustUQ;
     42        } else if (!strcasecmp (entry->statistic, "LQ")) {
     43            value = stats->robustLQ;
     44        } else {
     45            value = psStatsGetValue (stats, option);
     46        }
     47        entry->value = psMetadataItemAllocF32(entry->keyword, entry->statistic, value);
     48        psFree(stats);
    6249    }
    6350    return true;
Note: See TracChangeset for help on using the changeset viewer.