From 4cf02d70bd93e3453f305e6326caaeae48aa869f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 2 Mar 2020 13:42:07 +0000 Subject: [PATCH] Clang static analyser warnings --- src/bufr_util.c | 3 +++ ..._accessor_class_data_apply_gdsnotpresent.c | 27 ++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/bufr_util.c b/src/bufr_util.c index 21842a3fe..3b0c29eaa 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -32,6 +32,9 @@ int compute_bufr_key_rank(grib_handle* h, grib_string_list* keys, const char* ke next = prev->next; } } + DebugAssert(next); + if (!next) return 0; + if (!next->value) { next->value = strdup(key); next->count = 0; diff --git a/src/grib_accessor_class_data_apply_gdsnotpresent.c b/src/grib_accessor_class_data_apply_gdsnotpresent.c index 1d8e5284c..84e1e572c 100644 --- a/src/grib_accessor_class_data_apply_gdsnotpresent.c +++ b/src/grib_accessor_class_data_apply_gdsnotpresent.c @@ -250,20 +250,23 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) a->name, number_of_points); if (latitude_of_first_point == 0) { - if (number_of_values && !coded_vals) - return GRIB_INTERNAL_ERROR; - for (i = 0; i < number_of_values; i++) - val[i] = coded_vals[i]; - for (i = number_of_values; i < number_of_points; i++) - val[i] = coded_vals[number_of_values - 1]; + for (i = 0; i < number_of_values; i++) { + DebugAssert(coded_vals); + if (coded_vals) val[i] = coded_vals[i]; + } + for (i = number_of_values; i < number_of_points; i++) { + DebugAssert(coded_vals); + if (coded_vals) val[i] = coded_vals[number_of_values - 1]; + } } else { - if ((ni-1) && !coded_vals) - return GRIB_INTERNAL_ERROR; - for (i = 0; i < ni - 1; i++) - val[i] = coded_vals[0]; - for (i = ni - 1; i < number_of_points; i++) - val[i] = coded_vals[i - ni + 1]; + for (i = 0; i < ni - 1; i++) { + DebugAssert(coded_vals); + if (coded_vals) val[i] = coded_vals[0]; + } + for (i = ni - 1; i < number_of_points; i++) { + if (coded_vals && (i - ni + 1) < number_of_values) val[i] = coded_vals[i - ni + 1]; + } } *len = number_of_points;