From 9cd5b141ef9de62e14d4399bae3c87d499396e57 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 17 Jan 2021 00:13:30 +0000 Subject: [PATCH] cppcheck warning: identicalConditionAfterEarlyExit --- ...rib_accessor_class_bufr_extract_area_subsets.c | 7 +------ ...accessor_class_bufr_extract_datetime_subsets.c | 7 +------ src/grib_accessor_class_bufr_simple_thinning.c | 6 +----- ...ib_accessor_class_data_apply_boustrophedonic.c | 8 +++++--- ...data_g1second_order_general_extended_packing.c | 8 +++++--- src/grib_accessor_class_data_g1secondary_bitmap.c | 2 +- src/grib_accessor_class_data_g22order_packing.c | 6 ++++-- src/grib_accessor_class_data_jpeg2000_packing.c | 6 ++++-- src/grib_accessor_class_dictionary.c | 4 ++-- src/grib_accessor_class_expanded_descriptors.c | 2 +- src/grib_accessor_class_g1area.c | 4 ++-- src/grib_accessor_class_latlon_increment.c | 2 +- src/grib_accessor_class_latlonvalues.c | 6 +++--- src/grib_accessor_class_rdbtime_guess_date.c | 2 +- src/grib_accessor_class_smart_table.c | 2 +- src/grib_accessor_class_sum.c | 15 +++++++++------ src/grib_accessor_class_times.c | 2 +- src/grib_accessor_class_to_integer.c | 2 +- 18 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/grib_accessor_class_bufr_extract_area_subsets.c b/src/grib_accessor_class_bufr_extract_area_subsets.c index b3bdec849..361078b04 100644 --- a/src/grib_accessor_class_bufr_extract_area_subsets.c +++ b/src/grib_accessor_class_bufr_extract_area_subsets.c @@ -332,14 +332,9 @@ static int select_area(grib_accessor* a) static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int err = 0; /*grib_accessor_bufr_extract_area_subsets *self =(grib_accessor_bufr_extract_area_subsets*)a;*/ if (*len == 0) return GRIB_SUCCESS; - err = select_area(a); - if (err) - return err; - - return err; + return select_area(a); } diff --git a/src/grib_accessor_class_bufr_extract_datetime_subsets.c b/src/grib_accessor_class_bufr_extract_datetime_subsets.c index aa6f7eff9..6ecbf799e 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.c +++ b/src/grib_accessor_class_bufr_extract_datetime_subsets.c @@ -473,14 +473,9 @@ static int select_datetime(grib_accessor* a) static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int err = 0; /*grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a;*/ if (*len == 0) return GRIB_SUCCESS; - err = select_datetime(a); - if (err) - return err; - - return err; + return select_datetime(a); } diff --git a/src/grib_accessor_class_bufr_simple_thinning.c b/src/grib_accessor_class_bufr_simple_thinning.c index 0cd62f2f4..a971c82a7 100644 --- a/src/grib_accessor_class_bufr_simple_thinning.c +++ b/src/grib_accessor_class_bufr_simple_thinning.c @@ -239,9 +239,5 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) if (err) return err; - err = grib_set_long(a->parent->h, self->doExtractSubsets, 1); - if (err) - return err; - - return err; + return grib_set_long(a->parent->h, self->doExtractSubsets, 1); } diff --git a/src/grib_accessor_class_data_apply_boustrophedonic.c b/src/grib_accessor_class_data_apply_boustrophedonic.c index 877d51b57..9ea232988 100644 --- a/src/grib_accessor_class_data_apply_boustrophedonic.c +++ b/src/grib_accessor_class_data_apply_boustrophedonic.c @@ -280,11 +280,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) values = (double*)grib_context_malloc_clear(a->parent->h->context, size * sizeof(double)); err = grib_get_double_array(a->parent->h, "codedValues", values, &size); - if (err) + if (err) { + grib_context_free(a->parent->h->context, values); return err; + } *val = values[idx]; grib_context_free(a->parent->h->context, values); - return err; + return GRIB_SUCCESS; } static int pack_double(grib_accessor* a, const double* val, size_t* len) @@ -367,7 +369,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) grib_context_free(a->context, values); - return ret; + return GRIB_SUCCESS; } static int get_native_type(grib_accessor* a) diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c index af8c3f44b..454472d39 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c @@ -328,11 +328,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); - if (err) + if (err) { + grib_context_free(a->context, values); return err; + } *val = values[idx]; grib_context_free(a->context, values); - return err; + return GRIB_SUCCESS; } static int unpack_double(grib_accessor* a, double* values, size_t* len) @@ -1889,7 +1891,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) grib_context_free(a->context, groupWidths); grib_context_free(a->context, firstOrderValues); - return ret; + return GRIB_SUCCESS; } static void destroy(grib_context* context, grib_accessor* a) diff --git a/src/grib_accessor_class_data_g1secondary_bitmap.c b/src/grib_accessor_class_data_g1secondary_bitmap.c index aa80534e9..71c704d5e 100644 --- a/src/grib_accessor_class_data_g1secondary_bitmap.c +++ b/src/grib_accessor_class_data_g1secondary_bitmap.c @@ -159,7 +159,7 @@ static int value_count(grib_accessor* a, long* count) return err; *count = expand_by * len; - return err; + return GRIB_SUCCESS; } static int pack_double(grib_accessor* a, const double* val, size_t* len) diff --git a/src/grib_accessor_class_data_g22order_packing.c b/src/grib_accessor_class_data_g22order_packing.c index 33c716b99..ad364dde3 100644 --- a/src/grib_accessor_class_data_g22order_packing.c +++ b/src/grib_accessor_class_data_g22order_packing.c @@ -951,11 +951,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); - if (err) + if (err) { + grib_context_free(a->context, values); return err; + } *val = values[idx]; grib_context_free(a->context, values); - return err; + return GRIB_SUCCESS; } static int value_count(grib_accessor* a, long* count) diff --git a/src/grib_accessor_class_data_jpeg2000_packing.c b/src/grib_accessor_class_data_jpeg2000_packing.c index 0f44d7f86..8f40e396f 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.c +++ b/src/grib_accessor_class_data_jpeg2000_packing.c @@ -591,9 +591,11 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); - if (err) + if (err) { + grib_context_free(a->context, values); return err; + } *val = values[idx]; grib_context_free(a->context, values); - return err; + return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_dictionary.c b/src/grib_accessor_class_dictionary.c index 725926c5d..4a7210903 100644 --- a/src/grib_accessor_class_dictionary.c +++ b/src/grib_accessor_class_dictionary.c @@ -368,7 +368,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) *val = atol(buffer); *len = 1; - return err; + return GRIB_SUCCESS; } static int unpack_double(grib_accessor* a, double* val, size_t* len) @@ -384,5 +384,5 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) *val = atof(buffer); *len = 1; - return err; + return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_expanded_descriptors.c b/src/grib_accessor_class_expanded_descriptors.c index fa5c72a0c..bee48fb9e 100644 --- a/src/grib_accessor_class_expanded_descriptors.c +++ b/src/grib_accessor_class_expanded_descriptors.c @@ -646,7 +646,7 @@ static int expand(grib_accessor* a) if (expanded) { self->expanded = expanded; grib_context_free(c, u); - return err; + return GRIB_SUCCESS; } if (!self->tablesAccessor) { diff --git a/src/grib_accessor_class_g1area.c b/src/grib_accessor_class_g1area.c index ec96560af..b56c00eb0 100644 --- a/src/grib_accessor_class_g1area.c +++ b/src/grib_accessor_class_g1area.c @@ -173,7 +173,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ret == GRIB_SUCCESS) *len = 4; - return ret; + return GRIB_SUCCESS; } static int unpack_double(grib_accessor* a, double* val, size_t* len) @@ -205,7 +205,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (ret == GRIB_SUCCESS) *len = 4; - return ret; + return GRIB_SUCCESS; } static void dump(grib_accessor* a, grib_dumper* dumper) diff --git a/src/grib_accessor_class_latlon_increment.c b/src/grib_accessor_class_latlon_increment.c index ec44929f5..e1a39792b 100644 --- a/src/grib_accessor_class_latlon_increment.c +++ b/src/grib_accessor_class_latlon_increment.c @@ -350,7 +350,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ret == GRIB_SUCCESS) *len = 1; - return ret; + return GRIB_SUCCESS; } static int is_missing(grib_accessor* a) diff --git a/src/grib_accessor_class_latlonvalues.c b/src/grib_accessor_class_latlonvalues.c index 571c81042..e021ab2b6 100644 --- a/src/grib_accessor_class_latlonvalues.c +++ b/src/grib_accessor_class_latlonvalues.c @@ -184,14 +184,14 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) *len = size; - return ret; + return GRIB_SUCCESS; } static int value_count(grib_accessor* a, long* count) { grib_accessor_latlonvalues* self = (grib_accessor_latlonvalues*)a; grib_handle* h = grib_handle_of_accessor(a); - int ret; + int ret = GRIB_SUCCESS; size_t size; if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_ERROR, "unable to get size of %s", self->values); @@ -199,5 +199,5 @@ static int value_count(grib_accessor* a, long* count) } *count = 3 * size; - return ret; + return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_rdbtime_guess_date.c b/src/grib_accessor_class_rdbtime_guess_date.c index a3a31e69c..7239f9001 100644 --- a/src/grib_accessor_class_rdbtime_guess_date.c +++ b/src/grib_accessor_class_rdbtime_guess_date.c @@ -198,7 +198,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) *val = self->yearOrMonth == 1 ? rdbYear : rdbMonth; *len = 1; - return ret; + return GRIB_SUCCESS; } static int pack_long(grib_accessor* a, const long* v, size_t* len) diff --git a/src/grib_accessor_class_smart_table.c b/src/grib_accessor_class_smart_table.c index c9fd79550..b6d2c9a19 100644 --- a/src/grib_accessor_class_smart_table.c +++ b/src/grib_accessor_class_smart_table.c @@ -539,7 +539,7 @@ static int value_count(grib_accessor* a, long* count) return err; *count = self->tableCodesSize; - return err; + return GRIB_SUCCESS; } static void destroy(grib_context* context, grib_accessor* a) diff --git a/src/grib_accessor_class_sum.c b/src/grib_accessor_class_sum.c index 5c1750409..a1d9937c9 100644 --- a/src/grib_accessor_class_sum.c +++ b/src/grib_accessor_class_sum.c @@ -163,7 +163,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) if (size == 0) { *val = 0; - return ret; + return GRIB_SUCCESS; } values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); if (!values) @@ -177,7 +177,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) grib_context_free(a->context, values); - return ret; + return GRIB_SUCCESS; } static int unpack_double(grib_accessor* a, double* val, size_t* len) @@ -196,21 +196,24 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (size == 0) { *val = 0; - return ret; + return GRIB_SUCCESS; } values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); if (!values) return GRIB_OUT_OF_MEMORY; - grib_get_double_array(grib_handle_of_accessor(a), self->values, values, &size); - + ret = grib_get_double_array(grib_handle_of_accessor(a), self->values, values, &size); + if (ret) { + grib_context_free(a->context, values); + return ret; + } *val = 0; for (i = 0; i < size; i++) *val += values[i]; grib_context_free(a->context, values); - return ret; + return GRIB_SUCCESS; } static int value_count(grib_accessor* a, long* count) diff --git a/src/grib_accessor_class_times.c b/src/grib_accessor_class_times.c index 6e348d0a6..f4afef196 100644 --- a/src/grib_accessor_class_times.c +++ b/src/grib_accessor_class_times.c @@ -222,7 +222,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) *len = 1; - return ret; + return GRIB_SUCCESS; } static int value_count(grib_accessor* a, long* count) diff --git a/src/grib_accessor_class_to_integer.c b/src/grib_accessor_class_to_integer.c index f9f6e2677..83265a6ae 100644 --- a/src/grib_accessor_class_to_integer.c +++ b/src/grib_accessor_class_to_integer.c @@ -255,7 +255,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len) *v = strtol(val, &last, 10); /* if (*last) {err=GRIB_WRONG_CONVERSION;} */ - return err; + return GRIB_SUCCESS; } static int unpack_double(grib_accessor* a, double* v, size_t* len)