diff --git a/src/grib_accessor_class_data_g2bifourier_packing.c b/src/grib_accessor_class_data_g2bifourier_packing.c index f92f6a7b2..d947118e7 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.c +++ b/src/grib_accessor_class_data_g2bifourier_packing.c @@ -383,13 +383,9 @@ static double laplam(bif_trunc_t* bt, const double val[]) int i, j, k, l, isp; double zxmw, zymw, zwsum, zx, zy, zsum1, zsum2, zbeta1, zp; - itab1 = (int*)malloc(sizeof(int) * kmax); + itab1 = (int*)calloc(kmax, sizeof(int)); itab2 = (int*)malloc(sizeof(int) * ((1 + bt->bif_i) * (1 + bt->bif_j))); - for (k = 0; k < kmax; k++) { - itab1[k] = 0; - } - /* * Keep record of the possible values of i**2+j**2 outside the non-packed truncation */ @@ -419,16 +415,13 @@ static double laplam(bif_trunc_t* bt, const double val[]) * Now, itab2 contains all possible values of i*i+j*j, and itab1 contains * the rank of all i*i+j*j */ - znorm = (double*)malloc(sizeof(double) * lmax); + znorm = (double*)calloc(lmax, sizeof(double)); zw = (double*)malloc(sizeof(double) * lmax); /* * Compute norms of input field, gathered by values of i**2+j**2; we have to * go through the unpacked truncation again */ - for (l = 0; l < lmax; l++) - znorm[l] = 0.; - isp = 0; for_ij() { @@ -443,7 +436,7 @@ static double laplam(bif_trunc_t* bt, const double val[]) int m, ll = itab1[i * i + j * j]; for (m = 0; m < 4; m++, isp++) { DebugAssertAccess(znorm, (long)ll, (long)lmax); - DebugAssertAccess(val, (long)isp, bt->n_vals_bif); + DebugAssertAccess(val, (long)isp, (long)bt->n_vals_bif); if (ll < lmax && isp < bt->n_vals_bif) { znorm[ll] = MAX(znorm[ll], fabs(val[isp])); } @@ -631,6 +624,7 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a, grib_accessor_data_g2bifouri cleanup: free_bif_trunc(bt, a); + if (ret) fprintf(stderr, "ERROR: new_bif_trunc: %s\n", grib_get_error_message(ret)); return NULL; } diff --git a/src/grib_box_class.c b/src/grib_box_class.c index 86283ab86..eaf263d84 100644 --- a/src/grib_box_class.c +++ b/src/grib_box_class.c @@ -37,7 +37,6 @@ grib_box* grib_box_factory(grib_handle* h, grib_arguments* args) grib_box_class* c = *(table[i].cclass); grib_box* it = (grib_box*)grib_context_malloc_clear(h->context, c->size); it->cclass = c; - ret = GRIB_SUCCESS; ret = grib_box_init(it, h, args); if (ret == GRIB_SUCCESS) return it; diff --git a/src/grib_dumper_class_bufr_encode_C.c b/src/grib_dumper_class_bufr_encode_C.c index a1e052d70..efbf7201f 100644 --- a/src/grib_dumper_class_bufr_encode_C.c +++ b/src/grib_dumper_class_bufr_encode_C.c @@ -218,7 +218,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } sval = dval_to_string(c, values[i]); fprintf(self->dumper.out, "rvalues[%d]=%s;", i, sval); @@ -268,7 +267,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; double value = 0; - size_t size = 0; + size_t size = 0, size2 = 0; double* values = NULL; int err = 0; int i, icount; @@ -282,14 +281,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_value_count(a, &count); size = count; + size2 = size; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size); + err = grib_unpack_double(a, values, &size2); } else { - err = grib_unpack_double(a, &value, &size); + err = grib_unpack_double(a, &value, &size2); } + Assert(size == size2); self->empty = 0; @@ -522,7 +523,6 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } fprintf(self->dumper.out, "ivalues[%d]=%ld;", i, values[i]); diff --git a/src/grib_dumper_class_bufr_encode_filter.c b/src/grib_dumper_class_bufr_encode_filter.c index a61dfe6b2..892a17265 100644 --- a/src/grib_dumper_class_bufr_encode_filter.c +++ b/src/grib_dumper_class_bufr_encode_filter.c @@ -200,7 +200,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a) } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } fprintf(self->dumper.out, "%.18e", values[i]); @@ -245,7 +244,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* { grib_dumper_bufr_encode_filter* self = (grib_dumper_bufr_encode_filter*)d; double value = 0; - size_t size = 0; + size_t size = 0, size2 = 0; double* values = NULL; int err = 0; int i, icount; @@ -258,14 +257,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_value_count(a, &count); size = count; + size2 = size; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size); + err = grib_unpack_double(a, values, &size2); } else { - err = grib_unpack_double(a, &value, &size); + err = grib_unpack_double(a, &value, &size2); } + Assert(size == size2); self->empty = 0; diff --git a/src/grib_dumper_class_bufr_encode_fortran.c b/src/grib_dumper_class_bufr_encode_fortran.c index 3d08852f0..b8a2cff78 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.c +++ b/src/grib_dumper_class_bufr_encode_fortran.c @@ -315,7 +315,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; double value = 0; - size_t size = 0; + size_t size = 0, size2 = 0; double* values = NULL; int err = 0; int i, icount; @@ -329,14 +329,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_value_count(a, &count); size = count; + size2 = size; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size); + err = grib_unpack_double(a, values, &size2); } else { - err = grib_unpack_double(a, &value, &size); + err = grib_unpack_double(a, &value, &size2); } + Assert(size == size2); self->empty = 0; @@ -461,7 +463,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (icount > cols || i == 0) { fprintf(self->dumper.out, " &\n "); - icount = 0; } fprintf(self->dumper.out, "%ld ", values[size - 1]); @@ -526,7 +527,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; long value = 0; - size_t size = 0; + size_t size = 0, size2 = 0; long* values = NULL; int err = 0; int i, icount; @@ -540,14 +541,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr grib_value_count(a, &count); size = count; + size2 = size; 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(size == size2); self->empty = 0; diff --git a/src/grib_dumper_class_bufr_encode_python.c b/src/grib_dumper_class_bufr_encode_python.c index 4ddd50290..cb71ceaf8 100644 --- a/src/grib_dumper_class_bufr_encode_python.c +++ b/src/grib_dumper_class_bufr_encode_python.c @@ -269,7 +269,7 @@ 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; + size_t size = 0, size2 = 0; double* values = NULL; int err = 0; int i, icount; @@ -283,14 +283,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_value_count(a, &count); size = count; + size2 = size; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size); + err = grib_unpack_double(a, values, &size2); } else { - err = grib_unpack_double(a, &value, &size); + err = grib_unpack_double(a, &value, &size2); } + Assert(size == size2); self->empty = 0; @@ -310,7 +312,6 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } sval = dval_to_string(c, values[i]); fprintf(self->dumper.out, "%s", sval); @@ -414,7 +415,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } fprintf(self->dumper.out, "%ld", values[i]); diff --git a/src/grib_dumper_class_bufr_simple.c b/src/grib_dumper_class_bufr_simple.c index 2a00dbc7e..d1bd29a22 100644 --- a/src/grib_dumper_class_bufr_simple.c +++ b/src/grib_dumper_class_bufr_simple.c @@ -282,7 +282,6 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } fprintf(self->dumper.out, "%g", values[i]); @@ -343,6 +342,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) DebugAssert(!err); fprintf(self->dumper.out, "%s=%ld\n", a->name, value); DebugAssert(!grib_is_missing_long(a, value)); + (void)err; return; } @@ -398,7 +398,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } if (doing_unexpandedDescriptors) fprintf(self->dumper.out, "%06ld ", values[i]); @@ -483,7 +482,6 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr } if (icount > cols || i == 0) { fprintf(self->dumper.out, "\n "); - icount = 0; } fprintf(self->dumper.out, "%ld ", values[i]); fprintf(self->dumper.out, "}\n"); diff --git a/src/grib_dumper_class_debug.c b/src/grib_dumper_class_debug.c index 1d350a573..b3cc69e9e 100644 --- a/src/grib_dumper_class_debug.c +++ b/src/grib_dumper_class_debug.c @@ -281,7 +281,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; - err = _grib_get_string_length(a, &size); + _grib_get_string_length(a, &size); if ((size < 2) && grib_is_missing_internal(a)) { /* GRIB-302: transients and missing keys. Need to re-adjust the size */ size = 10; /* big enough to hold the string "missing" */ diff --git a/src/grib_dumper_class_wmo.c b/src/grib_dumper_class_wmo.c index 6db7f423c..13350bc70 100644 --- a/src/grib_dumper_class_wmo.c +++ b/src/grib_dumper_class_wmo.c @@ -304,7 +304,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) return; } - err = _grib_get_string_length(a, &size); + _grib_get_string_length(a, &size); value = (char*)grib_context_malloc_clear(a->context, size); if (!value) { grib_context_log(a->context, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); diff --git a/src/grib_handle.c b/src/grib_handle.c index b9762c09c..26e1fe557 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -1449,7 +1449,6 @@ grib_action* grib_action_from_filter(const char* filter) int grib_handle_apply_action(grib_handle* h, grib_action* a) { int err; - grib_action* ao = a; if (!a) return GRIB_SUCCESS; /* TODO: return error */ @@ -1461,15 +1460,12 @@ int grib_handle_apply_action(grib_handle* h, grib_action* a) a = a->next; } - a = ao; - return GRIB_SUCCESS; } int grib_handle_prepare_action(grib_handle* h, grib_action* a) { int err; - grib_action* ao = a; if (!a) return GRIB_SUCCESS; /* TODO: return error */ @@ -1481,8 +1477,6 @@ int grib_handle_prepare_action(grib_handle* h, grib_action* a) a = a->next; } - a = ao; - return GRIB_SUCCESS; } diff --git a/src/grib_parse_utils.c b/src/grib_parse_utils.c index bb73bed20..0b74b16ef 100644 --- a/src/grib_parse_utils.c +++ b/src/grib_parse_utils.c @@ -210,6 +210,7 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char else { ret = _grib_get_size(h, a, &size); } + if (ret) return ret; dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size); if (name[0] == '/' || name[0] == '#') { replen = size; @@ -250,6 +251,7 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char else { ret = _grib_get_size(h, a, &size); } + if (ret) return ret; lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size); if (name[0] == '/' || name[0] == '#') { replen = size;