From c4e98b03428f24e15fc3496c47d2a27148dd1ddf Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Dec 2022 11:39:54 +0000 Subject: [PATCH] Compiler warnings: use '%zu' in the format string for size_t --- src/grib_accessor_class_data_ccsds_packing.c | 4 ++-- src/grib_accessor_class_element.c | 4 ++-- src/grib_accessor_class_latitudes.c | 11 +++++------ src/grib_accessor_class_longitudes.c | 6 ++---- src/grib_dumper_class_debug.c | 4 ++-- src/grib_dumper_class_default.c | 4 ++-- src/grib_dumper_class_grib_encode_C.c | 8 +++----- src/grib_dumper_class_serialize.c | 6 +++--- src/grib_iterator_class_gaussian_reduced.c | 6 +++--- src/grib_util.c | 16 ++++++++-------- src/grib_value.c | 12 ++++++------ 11 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/grib_accessor_class_data_ccsds_packing.c b/src/grib_accessor_class_data_ccsds_packing.c index 7bdad0c52..370053fed 100644 --- a/src/grib_accessor_class_data_ccsds_packing.c +++ b/src/grib_accessor_class_data_ccsds_packing.c @@ -558,8 +558,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } /* - printf("n_vals = %ld, bits8 = %ld\n", (long)n_vals, (long)bits8); - printf("in %ld out => %ld\n", (long)bits8/8*n_vals,(long) buflen); + printf("n_vals = %ld, bits8 = %ld\n", n_vals, bits8); + printf("in %ld out => %zu\n", bits8/8*n_vals, buflen); */ buflen = strm.total_out; grib_buffer_replace(a, buf, buflen, 1, 1); diff --git a/src/grib_accessor_class_element.c b/src/grib_accessor_class_element.c index e57359d47..355cdf477 100644 --- a/src/grib_accessor_class_element.c +++ b/src/grib_accessor_class_element.c @@ -167,7 +167,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) ar = (long*)grib_context_malloc_clear(c, size * sizeof(long)); if (!ar) { - grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %ld bytes", size * sizeof(long)); + grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size * sizeof(long)); return GRIB_OUT_OF_MEMORY; } @@ -206,7 +206,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) ar = (long*)grib_context_malloc_clear(c, size * sizeof(long)); if (!ar) { - grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %ld bytes", size * sizeof(long)); + grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size * sizeof(long)); return GRIB_OUT_OF_MEMORY; } diff --git a/src/grib_accessor_class_latitudes.c b/src/grib_accessor_class_latitudes.c index 765050776..38f55767b 100644 --- a/src/grib_accessor_class_latitudes.c +++ b/src/grib_accessor_class_latitudes.c @@ -279,7 +279,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) double dummyLon = 0, dummyVal = 0; int ret = 0; int i; - long jScansPositively = 0; /*default: north to south*/ + long jScansPositively = 0; /* default: north to south */ size_t size = *len; grib_context* c = a->context; grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), 0, &ret); @@ -291,8 +291,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) } v = (double*)grib_context_malloc_clear(c, size * sizeof(double)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "Error allocating %ld bytes", (long)size * sizeof(double)); + grib_context_log(c, GRIB_LOG_ERROR, "Error allocating %zu bytes", size * sizeof(double)); return GRIB_OUT_OF_MEMORY; } *val = v; @@ -313,18 +312,18 @@ static int get_distinct(grib_accessor* a, double** val, long* len) v1 = (double*)grib_context_malloc_clear(c, size * sizeof(double)); if (!v1) { - grib_context_log(c, GRIB_LOG_ERROR, "Error allocating %ld bytes", (long)size * sizeof(double)); + grib_context_log(c, GRIB_LOG_ERROR, "Error allocating %zu bytes", size * sizeof(double)); return GRIB_OUT_OF_MEMORY; } - /*Construct a unique set of lats by filtering out duplicates*/ + /* Construct a unique set of lats by filtering out duplicates */ prev = v[0]; v1[0] = prev; count = 1; for (i = 1; i < *len; i++) { if (v[i] != prev) { prev = v[i]; - v1[count] = prev; /*Value different from previous so store it*/ + v1[count] = prev; /* Value different from previous so store it */ count++; } } diff --git a/src/grib_accessor_class_longitudes.c b/src/grib_accessor_class_longitudes.c index 9b52c36ee..a555d8d20 100644 --- a/src/grib_accessor_class_longitudes.c +++ b/src/grib_accessor_class_longitudes.c @@ -270,8 +270,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) } v = (double*)grib_context_malloc_clear(c, size * sizeof(double)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "Error allocating %ld bytes", (long)size * sizeof(double)); + grib_context_log(c, GRIB_LOG_ERROR, "Error allocating %zu bytes", size * sizeof(double)); return GRIB_OUT_OF_MEMORY; } *val = v; @@ -284,8 +283,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) v1 = (double*)grib_context_malloc_clear(c, size * sizeof(double)); if (!v1) { - grib_context_log(c, GRIB_LOG_ERROR, - "Error allocating %ld bytes", (long)size * sizeof(double)); + grib_context_log(c, GRIB_LOG_ERROR, "Error allocating %zu bytes", size * sizeof(double)); return GRIB_OUT_OF_MEMORY; } diff --git a/src/grib_dumper_class_debug.c b/src/grib_dumper_class_debug.c index c5c0e91d4..7ffc94cad 100644 --- a/src/grib_dumper_class_debug.c +++ b/src/grib_dumper_class_debug.c @@ -347,7 +347,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) if (size == 0) fprintf(self->dumper.out, "}\n"); else - fprintf(self->dumper.out, " *** ERR cannot malloc(%ld) }\n", (long)size); + fprintf(self->dumper.out, " *** ERR cannot malloc(%zu) }\n", size); return; } @@ -424,7 +424,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size == 0) fprintf(self->dumper.out, "}\n"); else - fprintf(self->dumper.out, " *** ERR cannot malloc(%ld) }\n", (long)size); + fprintf(self->dumper.out, " *** ERR cannot malloc(%zu) }\n", size); return; } diff --git a/src/grib_dumper_class_default.c b/src/grib_dumper_class_default.c index 13608ec85..ab08d535f 100644 --- a/src/grib_dumper_class_default.c +++ b/src/grib_dumper_class_default.c @@ -585,7 +585,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) else fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%s(%ld) = ", a->name, (long)size); + fprintf(self->dumper.out, "%s(%zu) = ", a->name, size); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -593,7 +593,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size == 0) fprintf(self->dumper.out, "}\n"); else - fprintf(self->dumper.out, " *** ERR cannot malloc(%ld) }\n", (long)size); + fprintf(self->dumper.out, " *** ERR cannot malloc(%zu) }\n", size); return; } diff --git a/src/grib_dumper_class_grib_encode_C.c b/src/grib_dumper_class_grib_encode_C.c index 8472d78bf..b9c06653a 100644 --- a/src/grib_dumper_class_grib_encode_C.c +++ b/src/grib_dumper_class_grib_encode_C.c @@ -253,7 +253,6 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = a->length; unsigned char* buf; - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return; @@ -263,11 +262,10 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) buf = (unsigned char*)grib_context_malloc(d->context, size); if (!buf) { - fprintf(self->dumper.out, "/* %s: cannot malloc(%ld) */\n", a->name, (long)size); + fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name, size); return; } - err = grib_unpack_bytes(a, buf, &size); if (err) { grib_context_free(d->context, buf); @@ -336,7 +334,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) buf = (double*)grib_context_malloc(d->context, size * sizeof(double)); if (!buf) { - fprintf(self->dumper.out, "/* %s: cannot malloc(%ld) */\n", a->name, (long)size); + fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name, size); return; } @@ -348,7 +346,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) return; } - fprintf(self->dumper.out, " size = %ld;\n", (long)size); + fprintf(self->dumper.out, " size = %zu;\n", size); fprintf(self->dumper.out, " v%s = (%s*)calloc(size,sizeof(%s));\n", stype, stype, stype); fprintf(self->dumper.out, " if(!v%s) {\n", stype); fprintf(self->dumper.out, " fprintf(stderr,\"failed to allocate %%d bytes\\n\",size*sizeof(%s));\n", stype); diff --git a/src/grib_dumper_class_serialize.c b/src/grib_dumper_class_serialize.c index bc4ff9051..d083a7fa7 100644 --- a/src/grib_dumper_class_serialize.c +++ b/src/grib_dumper_class_serialize.c @@ -262,7 +262,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) if (size == 0) fprintf(self->dumper.out, "}\n"); else - fprintf(self->dumper.out, " *** ERR cannot malloc(%ld) }\n", (long)size); + fprintf(self->dumper.out, " *** ERR cannot malloc(%zu) }\n", size); return; } @@ -371,13 +371,13 @@ static void dump_values(grib_dumper* d, grib_accessor* a) buf = (double*)grib_context_malloc(d->context, size * sizeof(double)); - fprintf(self->dumper.out, "%s (%ld) {", a->name, (long)size); + fprintf(self->dumper.out, "%s (%zu) {", a->name, size); if (!buf) { if (size == 0) fprintf(self->dumper.out, "}\n"); else - fprintf(self->dumper.out, " *** ERR cannot malloc(%ld) }\n", (long)size); + fprintf(self->dumper.out, " *** ERR cannot malloc(%zu) }\n", size); return; } diff --git a/src/grib_iterator_class_gaussian_reduced.c b/src/grib_iterator_class_gaussian_reduced.c index fe57d970c..ace37923c 100644 --- a/src/grib_iterator_class_gaussian_reduced.c +++ b/src/grib_iterator_class_gaussian_reduced.c @@ -168,7 +168,7 @@ static int iterate_reduced_gaussian_subarea_legacy(grib_iterator* iter, grib_han if (h->context->debug) { const size_t np = count_subarea_points(h, get_reduced_row, pl, plsize, lon_first, lon_last); - fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: Legacy sub-area num points=%ld\n", (long)np); + fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: Legacy sub-area num points=%zu\n", np); } /*find starting latitude */ @@ -222,7 +222,7 @@ static int iterate_reduced_gaussian_subarea_algorithm2(grib_iterator* iter, grib if (h->context->debug) { const size_t np = count_subarea_points(h, get_reduced_row, pl, plsize, lon_first, lon_last); - fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: sub-area num points=%ld\n", (long)np); + fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: sub-area num points=%zu\n", np); } /* Find starting latitude */ @@ -381,7 +381,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) iter->e = 0; if (h->context->debug) { const size_t np = count_global_points(pl, plsize); - fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: global num points=%ld\n", (long)np); + fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: global num points=%zu\n", np); } for (j = 0; j < plsize; j++) { diff --git a/src/grib_util.c b/src/grib_util.c index 6e978142e..362a4e168 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -389,7 +389,7 @@ static void print_values(grib_context* c, for (i = 0; i < count; i++) { switch (keyval_pairs[i].type) { case GRIB_TYPE_LONG: - fprintf(stderr, "ECCODES DEBUG grib_util: => %s = %ld;\n", keyval_pairs[i].name, (long)keyval_pairs[i].long_value); + fprintf(stderr, "ECCODES DEBUG grib_util: => %s = %ld;\n", keyval_pairs[i].name, keyval_pairs[i].long_value); break; case GRIB_TYPE_DOUBLE: fprintf(stderr, "ECCODES DEBUG grib_util: => %s = %.16e;\n", keyval_pairs[i].name, keyval_pairs[i].double_value); @@ -629,8 +629,8 @@ static int check_geometry(grib_handle* handle, const grib_util_grid_spec2* spec, strcpy(msg, "Specified to be global (in spec)"); sum = sum_of_pl_array(spec->pl, spec->pl_size); if (sum != data_values_count) { - fprintf(stderr, "GRIB_UTIL_SET_SPEC: Invalid reduced gaussian grid: %s but data_values_count != sum_of_pl_array (%ld!=%ld)\n", - msg, (long)data_values_count, (long)sum); + fprintf(stderr, "GRIB_UTIL_SET_SPEC: Invalid reduced gaussian grid: %s but data_values_count != sum_of_pl_array (%zu!=%zu)\n", + msg, data_values_count, sum); return GRIB_WRONG_GRID; } } @@ -1301,7 +1301,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h, setSecondOrder = 1; break; default: - fprintf(stderr, "GRIB_UTIL_SET_SPEC: invalid packing_spec.packing_type (%ld)\n", (long)packing_spec->packing_type); + fprintf(stderr, "GRIB_UTIL_SET_SPEC: invalid packing_spec.packing_type (%ld)\n", packing_spec->packing_type); *err = GRIB_INTERNAL_ERROR; goto cleanup; break; @@ -1364,7 +1364,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h, break; default: - fprintf(stderr, "GRIB_UTIL_SET_SPEC: invalid packing_spec.accuracy (%ld)\n", (long)packing_spec->accuracy); + fprintf(stderr, "GRIB_UTIL_SET_SPEC: invalid packing_spec.accuracy (%ld)\n", packing_spec->accuracy); grib_handle_delete(h_sample); *err = GRIB_INTERNAL_ERROR; goto cleanup; @@ -1423,8 +1423,8 @@ grib_handle* grib_util_set_spec2(grib_handle* h, size_t sum = sum_of_pl_array(spec->pl, spec->pl_size); if (data_values_count != sum) { fprintf(stderr, "GRIB_UTIL_SET_SPEC: invalid reduced gaussian grid: " - "specified as global, data_values_count=%ld but sum of pl array=%ld\n", - (long)data_values_count, (long)sum); + "specified as global, data_values_count=%zu but sum of pl array=%zu\n", + data_values_count, sum); *err = GRIB_WRONG_GRID; goto cleanup; } @@ -1469,7 +1469,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h, ferror = fopen("error.data", "w"); lcount = 0; - fprintf(ferror, "# data_values_count=%ld\n", (long)data_values_count); + fprintf(ferror, "# data_values_count=%zu\n", data_values_count); fprintf(ferror, "set values={ "); for (ii = 0; ii < data_values_count - 1; ii++) { fprintf(ferror, "%g, ", data_values[ii]); diff --git a/src/grib_value.c b/src/grib_value.c index 1dc801a3e..5ddb7040c 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -36,7 +36,7 @@ static void print_debug_info__set_double_array(grib_handle* h, const char* func, if (length <= N) N = length; - fprintf(stderr, "ECCODES DEBUG %s key=%s %lu values (", func, name, (unsigned long)length); + fprintf(stderr, "ECCODES DEBUG %s key=%s %zu values (", func, name, length); for (i = 0; i < N; ++i) { if (i != 0) fprintf(stderr,", "); fprintf(stderr, "%.10g", val[i]); @@ -93,7 +93,7 @@ int grib_set_long_internal(grib_handle* h, const char* name, long val) a = grib_find_accessor(h, name); if (h->context->debug) - fprintf(stderr, "ECCODES DEBUG grib_set_long_internal %s=%ld\n", name, (long)val); + fprintf(stderr, "ECCODES DEBUG grib_set_long_internal %s=%ld\n", name, val); if (a) { ret = grib_pack_long(a, &val, &l); @@ -121,9 +121,9 @@ int grib_set_long(grib_handle* h, const char* name, long val) if (a) { if (h->context->debug) { if (strcmp(name, a->name)!=0) - fprintf(stderr, "ECCODES DEBUG grib_set_long %s=%ld (a->name=%s)\n", name, (long)val, a->name); + fprintf(stderr, "ECCODES DEBUG grib_set_long %s=%ld (a->name=%s)\n", name, val, a->name); else - fprintf(stderr, "ECCODES DEBUG grib_set_long %s=%ld\n", name, (long)val); + fprintf(stderr, "ECCODES DEBUG grib_set_long %s=%ld\n", name, val); } if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) @@ -491,7 +491,7 @@ int grib_set_string_array(grib_handle* h, const char* name, const char** val, si a = grib_find_accessor(h, name); if (h->context->debug) { - fprintf(stderr, "ECCODES DEBUG grib_set_string_array key=%s %ld values\n", name, (long)length); + fprintf(stderr, "ECCODES DEBUG grib_set_string_array key=%s %zu values\n", name, length); } if (a) { @@ -899,7 +899,7 @@ static int _grib_set_long_array(grib_handle* h, const char* name, const long* va size_t N = 5; if (length <= N) N = length; - fprintf(stderr, "ECCODES DEBUG _grib_set_long_array key=%s %ld values (", name, (long)length); + fprintf(stderr, "ECCODES DEBUG _grib_set_long_array key=%s %zu values (", name, length); for (i = 0; i < N; ++i) fprintf(stderr, " %ld,", val[i]); if (N >= length)