From 76dfc35268b06ebb3de519df3eafb1ca14c38895 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 27 Feb 2020 13:12:49 +0000 Subject: [PATCH] Clang static analyser warnings --- ..._accessor_class_data_apply_gdsnotpresent.c | 10 ++++--- src/grib_box_class_reduced_gaussian.c | 6 ++-- src/grib_dumper_class_bufr_encode_python.c | 28 +++++++++---------- tigge/tigge_accumulations.c | 2 ++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/grib_accessor_class_data_apply_gdsnotpresent.c b/src/grib_accessor_class_data_apply_gdsnotpresent.c index 7d6fec79d..1d8e5284c 100644 --- a/src/grib_accessor_class_data_apply_gdsnotpresent.c +++ b/src/grib_accessor_class_data_apply_gdsnotpresent.c @@ -200,9 +200,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) long nn = 0; int err = 0; size_t size = 0; - long missing_value; - - double* coded_vals = NULL; + long missing_value = 0; + double* coded_vals = NULL; err = grib_value_count(a, &nn); n_vals = nn; @@ -231,7 +230,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (number_of_values > 0) { coded_vals = (double*)grib_context_malloc(a->context, number_of_values * sizeof(double)); - if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; } @@ -252,12 +250,16 @@ 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]; } 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++) diff --git a/src/grib_box_class_reduced_gaussian.c b/src/grib_box_class_reduced_gaussian.c index 151d170a0..fd7c8cc4c 100644 --- a/src/grib_box_class_reduced_gaussian.c +++ b/src/grib_box_class_reduced_gaussian.c @@ -208,8 +208,10 @@ static grib_points* get_points(grib_box* box, double north, double west, double grib_context* c = box->context; points = grib_points_new(c, self->size); - if (!points) - grib_context_log(c, GRIB_LOG_FATAL, "unable to create grib_points\n"); + if (!points) { + grib_context_log(c, GRIB_LOG_ERROR, "unable to create grib_points\n"); + return NULL; + } index = 0; l = 0; diff --git a/src/grib_dumper_class_bufr_encode_python.c b/src/grib_dumper_class_bufr_encode_python.c index 57ddaa8b6..01ca57b54 100644 --- a/src/grib_dumper_class_bufr_encode_python.c +++ b/src/grib_dumper_class_bufr_encode_python.c @@ -174,8 +174,8 @@ static void dump_values(grib_dumper* d, grib_accessor* a) grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; + double* values = NULL; + int err = 0; int i, r, icount; int cols = 2; long count = 0; @@ -270,9 +270,8 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; - int i, icount; + double* values = NULL; + int err = 0, i = 0, icount = 0; int cols = 2; long count = 0; char* sval; @@ -352,9 +351,8 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; long value = 0; size_t size = 0, size2 = 0; - long* values = NULL; - int err = 0; - int i, r, icount; + long* values = NULL; + int err = 0, i = 0, r = 0, icount = 0; int cols = 4; long count = 0; char* sval = NULL; @@ -483,10 +481,9 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr { grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; long value = 0; - size_t size = 0; - long* values = NULL; - int err = 0; - int i, icount; + size_t size = 0, size2 = 0; + long* values = NULL; + int err = 0, i = 0, icount = 0; int cols = 4; long count = 0; grib_context* c = a->context; @@ -495,15 +492,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr return; grib_value_count(a, &count); - size = count; + size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size); + err = grib_unpack_long(a, values, &size2); } else { - err = grib_unpack_long(a, &value, &size); + err = grib_unpack_long(a, &value, &size2); } + Assert(size2 == size); self->empty = 0; diff --git a/tigge/tigge_accumulations.c b/tigge/tigge_accumulations.c index a8d4180f9..f5d12151d 100755 --- a/tigge/tigge_accumulations.c +++ b/tigge/tigge_accumulations.c @@ -265,6 +265,8 @@ int main(int argc, char *argv[]) if(result) grib_handle_delete(result); + free(values); + if(fclose(out)) { perror(argv[argc-1]);