From 9222fe2873e74fb59e189e6efcca37fef80d567f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 20 Feb 2020 12:03:49 +0000 Subject: [PATCH] ECC-992: Adjust min. limit for 247 --- definitions/param_limits.def | 2 +- examples/C/grib_nearest_multiple.c | 24 ++++++----- fortran/grib_fortran.c | 48 +++++++++++----------- src/bufr_util.c | 6 ++- src/grib_accessor.c | 2 +- src/grib_accessor_class.c | 4 +- src/grib_accessor_class_data_png_packing.c | 1 - src/grib_accessor_class_g1_increment.c | 2 +- src/grib_accessor_class_longitudes.c | 1 - tests/unit_tests.c | 3 ++ 10 files changed, 51 insertions(+), 42 deletions(-) diff --git a/definitions/param_limits.def b/definitions/param_limits.def index 6b5c95af7..e04fb9053 100644 --- a/definitions/param_limits.def +++ b/definitions/param_limits.def @@ -70,7 +70,7 @@ concept param_value_min(default_min_val) { 170 = { paramId=228096; } 170 = { paramId=228095; } 0 = { paramId=43; } - 0 = { paramId=247; } + -0.01 = { paramId=247; } 0 = { paramId=246; } -0.1 = { paramId=133; } 43000 = { paramId=134; } diff --git a/examples/C/grib_nearest_multiple.c b/examples/C/grib_nearest_multiple.c index c32bc9b93..717936dc1 100644 --- a/examples/C/grib_nearest_multiple.c +++ b/examples/C/grib_nearest_multiple.c @@ -59,50 +59,54 @@ int main(int argc, char** argv) while (fscanf(fin, "%ld %g %g", &iid, &lat, &lon) != EOF) npoints++; fclose(fin); + if (npoints==0) { + fprintf(stderr, "No input points found!\n"); + exit(1); + } id = (long*)calloc(npoints, sizeof(long)); if (!id) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(long))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(long))); exit(1); } vlat = (double*)calloc(npoints, sizeof(double)); if (!vlat) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } vlon = (double*)calloc(npoints, sizeof(double)); if (!vlon) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } outlats = (double*)calloc(npoints, sizeof(double)); if (!outlats) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } outlons = (double*)calloc(npoints, sizeof(double)); if (!outlons) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } values = (double*)calloc(npoints, sizeof(double)); if (!values) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } lsm_values = (double*)calloc(npoints, sizeof(double)); if (!lsm_values) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } distances = (double*)calloc(npoints, sizeof(double)); if (!distances) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(double))); exit(1); } indexes = (int*)calloc(npoints, sizeof(int)); if (!indexes) { - printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(int))); + fprintf(stderr, "unable to allocate %ld bytes\n", (long)(npoints * sizeof(int))); exit(1); } @@ -132,7 +136,7 @@ int main(int argc, char** argv) } h = codes_handle_new_from_file(0, fin, PRODUCT_GRIB, &ret); if (!h || ret != CODES_SUCCESS) { - printf(" unable to create handle\n"); + fprintf(stderr, "unable to create handle\n"); exit(1); } diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index cab1e8547..289e2c5b4 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -316,24 +316,24 @@ static void _push_handle(grib_handle *h,int *gid) static void _push_index(grib_index *h,int *gid) { - l_grib_index* current= index_set; + l_grib_index* current= NULL; l_grib_index* previous= index_set; l_grib_index* the_new= NULL; int myindex= 1; /* - if (*gid > 0 ) { - while(current) { - if(current->id == *gid) break; - current = current->next; + if (*gid > 0 ) { + while(current) { + if(current->id == *gid) break; + current = current->next; + } + if (current) { + grib_index_delete(current->h); + current->h=h; + return; + } } - if (current) { - grib_index_delete(current->h); - current->h=h; - return; - } - } - */ + */ if(!index_set){ index_set = (l_grib_index*)malloc(sizeof(l_grib_index)); @@ -374,24 +374,24 @@ static void _push_index(grib_index *h,int *gid) static void _push_multi_handle(grib_multi_handle *h,int *gid) { - l_grib_multi_handle* current= multi_handle_set; + l_grib_multi_handle* current= NULL; l_grib_multi_handle* previous= multi_handle_set; l_grib_multi_handle* the_new= NULL; int myindex= 1; /* - if (*gid > 0 ) { - while(current) { - if(current->id == *gid) break; - current = current->next; + if (*gid > 0 ) { + while(current) { + if(current->id == *gid) break; + current = current->next; + } + if (current) { + grib_multi_handle_delete(current->h); + current->h=h; + return; + } } - if (current) { - grib_multi_handle_delete(current->h); - current->h=h; - return; - } - } - */ + */ if(!multi_handle_set){ multi_handle_set = (l_grib_multi_handle*)malloc(sizeof(l_grib_multi_handle)); diff --git a/src/bufr_util.c b/src/bufr_util.c index 8211d9b41..607d88a76 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -27,8 +27,10 @@ int compute_bufr_key_rank(grib_handle* h, grib_string_list* keys, const char* ke } if (!next) { DebugAssert(prev); - prev->next = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); - next = prev->next; + if (prev) { + prev->next = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); + next = prev->next; + } } if (!next->value) { next->value = strdup(key); diff --git a/src/grib_accessor.c b/src/grib_accessor.c index 4760fd954..b1be492cd 100644 --- a/src/grib_accessor.c +++ b/src/grib_accessor.c @@ -430,7 +430,7 @@ int grib_accessor_notify_change(grib_accessor* a, grib_accessor* changed) return c->notify_change(a, changed); c = c->super ? *(c->super) : NULL; } - if (a) + if (a && a->cclass) printf("notify_change not implemented for %s %s\n", a->cclass->name, a->name); Assert(0); return 0; diff --git a/src/grib_accessor_class.c b/src/grib_accessor_class.c index f21af388b..7b470f217 100644 --- a/src/grib_accessor_class.c +++ b/src/grib_accessor_class.c @@ -325,8 +325,10 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth) else { if (!s->h->partial) { if (length >= plen) { - grib_context_log(s->h->context, GRIB_LOG_ERROR, "Invalid size %ld found for %s, assuming %ld", + if (s->owner) { + grib_context_log(s->h->context, GRIB_LOG_ERROR, "Invalid size %ld found for %s, assuming %ld", (long)plen, s->owner->name, (long)length); + } plen = length; } s->padding = plen - length; diff --git a/src/grib_accessor_class_data_png_packing.c b/src/grib_accessor_class_data_png_packing.c index 1e452e4b3..7632bb403 100644 --- a/src/grib_accessor_class_data_png_packing.c +++ b/src/grib_accessor_class_data_png_packing.c @@ -249,7 +249,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) self->dirty = 0; - n_vals = 0; err = grib_value_count(a, &nn); n_vals = nn; if (err) diff --git a/src/grib_accessor_class_g1_increment.c b/src/grib_accessor_class_g1_increment.c index 280df2b4b..eadc64573 100644 --- a/src/grib_accessor_class_g1_increment.c +++ b/src/grib_accessor_class_g1_increment.c @@ -167,7 +167,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) long numberOfPoints = 0; if (*len < 1) - ret = GRIB_ARRAY_TOO_SMALL; + return GRIB_ARRAY_TOO_SMALL; if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->directionIncrementGiven, &directionIncrementGiven)) != GRIB_SUCCESS) return ret; diff --git a/src/grib_accessor_class_longitudes.c b/src/grib_accessor_class_longitudes.c index 9b3b40608..b64c3225e 100644 --- a/src/grib_accessor_class_longitudes.c +++ b/src/grib_accessor_class_longitudes.c @@ -174,7 +174,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) grib_iterator* iter = NULL; self->save = 1; - size = 0; ret = value_count(a, &count); if (ret) return ret; diff --git a/tests/unit_tests.c b/tests/unit_tests.c index db2f37a9f..b2bca6944 100644 --- a/tests/unit_tests.c +++ b/tests/unit_tests.c @@ -1378,6 +1378,7 @@ static void test_string_splitting() char input[80] = "Born|To|Be|Wild"; char** list = 0; list = string_split(input, "|"); + assert(list); for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */ assert(i == 4); if (strcmp(list[0], "Born") != 0) assert(0); @@ -1391,6 +1392,7 @@ static void test_string_splitting() strcpy(input, "12345|a gap|"); list = string_split(input, "|"); + assert(list); for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */ assert(i == 2); if (strcmp(list[0], "12345") != 0) assert(0); @@ -1402,6 +1404,7 @@ static void test_string_splitting() strcpy(input, "Steppenwolf"); list = string_split(input, ","); + assert(list); for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */ assert(i == 1); if (strcmp(list[0], "Steppenwolf") != 0) assert(0);