Examples: use '%zu' in the format string for size_t

This commit is contained in:
Shahram Najm 2022-12-21 15:07:48 +00:00
parent 55e9287fab
commit 0908028394
11 changed files with 45 additions and 48 deletions

View File

@ -321,7 +321,8 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len)
{ {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret = 0, i, idx; int ret = GRIB_SUCCESS, idx = 0;
size_t i = 0;
char* s = NULL; char* s = NULL;
grib_context* c = a->context; grib_context* c = a->context;
@ -420,7 +421,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
{ {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret = 0, idx; int ret = GRIB_SUCCESS, idx = 0;
char* s = NULL; char* s = NULL;
grib_context* c = a->context; grib_context* c = a->context;
@ -442,8 +443,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
static int unpack_long(grib_accessor* a, long* val, size_t* len) static int unpack_long(grib_accessor* a, long* val, size_t* len)
{ {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret = 0, i; int ret = GRIB_SUCCESS;
long count = 0; long count = 0, i = 0;
value_count(a, &count); value_count(a, &count);
@ -471,8 +472,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
static int unpack_double(grib_accessor* a, double* val, size_t* len) static int unpack_double(grib_accessor* a, double* val, size_t* len)
{ {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret = 0, i; int ret = GRIB_SUCCESS;
long count = 0; long count = 0, i = 0;
value_count(a, &count); value_count(a, &count);
@ -500,8 +501,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
static int pack_double(grib_accessor* a, const double* val, size_t* len) static int pack_double(grib_accessor* a, const double* val, size_t* len)
{ {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret = 0, i; int ret = GRIB_SUCCESS;
long count = 1; long count = 1, i = 0;
grib_context* c = a->context; grib_context* c = a->context;
if (self->compressedData) { if (self->compressedData) {

View File

@ -84,7 +84,7 @@ static void* default_long_lasting_malloc(const grib_context* c, size_t size)
void* ret; void* ret;
ret = malloc(size); ret = malloc(size);
if (!ret) { if (!ret) {
grib_context_log(c, GRIB_LOG_FATAL, "default_long_lasting_malloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "default_long_lasting_malloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return ret; return ret;
@ -100,7 +100,7 @@ static void* default_buffer_malloc(const grib_context* c, size_t size)
void* ret; void* ret;
ret = malloc(size); ret = malloc(size);
if (!ret) { if (!ret) {
grib_context_log(c, GRIB_LOG_FATAL, "default_buffer_malloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "default_buffer_malloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return ret; return ret;
@ -111,7 +111,7 @@ static void* default_buffer_realloc(const grib_context* c, void* p, size_t size)
void* ret; void* ret;
ret = realloc(p, size); ret = realloc(p, size);
if (!ret) { if (!ret) {
grib_context_log(c, GRIB_LOG_FATAL, "default_buffer_realloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "default_buffer_realloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return ret; return ret;
@ -127,7 +127,7 @@ static void* default_malloc(const grib_context* c, size_t size)
void* ret; void* ret;
ret = malloc(size); ret = malloc(size);
if (!ret) { if (!ret) {
grib_context_log(c, GRIB_LOG_FATAL, "default_malloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "default_malloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return ret; return ret;
@ -138,7 +138,7 @@ static void* default_realloc(const grib_context* c, void* p, size_t size)
void* ret; void* ret;
ret = realloc(p, size); ret = realloc(p, size);
if (!ret) { if (!ret) {
grib_context_log(c, GRIB_LOG_FATAL, "default_realloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "default_realloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return ret; return ret;
@ -905,7 +905,7 @@ void* grib_context_malloc_persistent(const grib_context* c, size_t size)
void* p = c->alloc_persistent_mem(c, size); void* p = c->alloc_persistent_mem(c, size);
if (!p) { if (!p) {
grib_context_log(c, GRIB_LOG_FATAL, grib_context_log(c, GRIB_LOG_FATAL,
"grib_context_malloc_persistent: error allocating %lu bytes", (unsigned long)size); "grib_context_malloc_persistent: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return p; return p;
@ -937,7 +937,7 @@ void* grib_context_malloc(const grib_context* c, size_t size)
else else
p = c->alloc_mem(c, size); p = c->alloc_mem(c, size);
if (!p) { if (!p) {
grib_context_log(c, GRIB_LOG_FATAL, "grib_context_malloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "grib_context_malloc: error allocating %zu bytes", size);
Assert(0); Assert(0);
} }
return p; return p;
@ -950,7 +950,7 @@ void* grib_context_realloc(const grib_context* c, void* p, size_t size)
c = grib_context_get_default(); c = grib_context_get_default();
q = c->realloc_mem(c, p, size); q = c->realloc_mem(c, p, size);
if (!q) { if (!q) {
grib_context_log(c, GRIB_LOG_FATAL, "grib_context_realloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "grib_context_realloc: error allocating %zu bytes", size);
return NULL; return NULL;
} }
return q; return q;
@ -985,7 +985,7 @@ void* grib_context_buffer_malloc(const grib_context* c, size_t size)
else else
p = c->alloc_buffer_mem(c, size); p = c->alloc_buffer_mem(c, size);
if (!p) { if (!p) {
grib_context_log(c, GRIB_LOG_FATAL, "grib_context_buffer_malloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "grib_context_buffer_malloc: error allocating %zu bytes", size);
return NULL; return NULL;
} }
return p; return p;
@ -1003,7 +1003,7 @@ void* grib_context_buffer_realloc(const grib_context* c, void* p, size_t size)
{ {
void* q = c->realloc_buffer_mem(c, p, size); void* q = c->realloc_buffer_mem(c, p, size);
if (!q) { if (!q) {
grib_context_log(c, GRIB_LOG_FATAL, "grib_context_buffer_realloc: error allocating %lu bytes", (unsigned long)size); grib_context_log(c, GRIB_LOG_FATAL, "grib_context_buffer_realloc: error allocating %zu bytes", size);
return NULL; return NULL;
} }
return q; return q;

View File

@ -15,9 +15,9 @@ void grib_darray_print(const char* title, const grib_darray* darray)
{ {
size_t i; size_t i;
Assert(darray); Assert(darray);
printf("%s: darray.n=%lu \t", title, (unsigned long)darray->n); printf("%s: darray.n=%zu \t", title, darray->n);
for (i = 0; i < darray->n; i++) { for (i = 0; i < darray->n; i++) {
printf("darray[%lu]=%g\t", (unsigned long)i, darray->v[i]); printf("darray[%zu]=%g\t", i, darray->v[i]);
} }
printf("\n"); printf("\n");
} }

View File

@ -9,9 +9,7 @@
*/ */
/*************************************************************************** /***************************************************************************
*
* Enrico Fucile * Enrico Fucile
*
***************************************************************************/ ***************************************************************************/
#include "grib_api_internal.h" #include "grib_api_internal.h"
@ -21,9 +19,9 @@ void grib_iarray_print(const char* title, const grib_iarray* iarray)
{ {
size_t i; size_t i;
Assert(iarray); Assert(iarray);
printf("%s: iarray.n=%lu \t", title, (unsigned long)iarray->n); printf("%s: iarray.n=%zu \t", title, iarray->n);
for (i = 0; i < iarray->n; i++) { for (i = 0; i < iarray->n; i++) {
printf("iarray[%lu]=%ld\t", (unsigned long)i, iarray->v[i]); printf("iarray[%zu]=%ld\t", i, iarray->v[i]);
} }
printf("\n"); printf("\n");
} }

View File

@ -384,7 +384,7 @@ static void print_values(grib_context* c,
size_t i = 0; size_t i = 0;
int isConstant = 1; int isConstant = 1;
double v = 0, minVal = DBL_MAX, maxVal = -DBL_MAX; double v = 0, minVal = DBL_MAX, maxVal = -DBL_MAX;
fprintf(stderr, "ECCODES DEBUG grib_util: grib_set_values, setting %lu key/value pairs\n", (unsigned long)count); fprintf(stderr, "ECCODES DEBUG grib_util: grib_set_values, setting %zu key/value pairs\n", count);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
switch (keyval_pairs[i].type) { switch (keyval_pairs[i].type) {
@ -400,7 +400,7 @@ static void print_values(grib_context* c,
} }
} }
fprintf(stderr, "ECCODES DEBUG grib_util: data_values_count=%lu;\n", (unsigned long)data_values_count); fprintf(stderr, "ECCODES DEBUG grib_util: data_values_count=%zu;\n", data_values_count);
for (i = 0; i < data_values_count; i++) { for (i = 0; i < data_values_count; i++) {
if (i == 0) if (i == 0)
v = data_values[i]; v = data_values[i];

View File

@ -22,9 +22,9 @@ void grib_vdarray_print(const char* title, const grib_vdarray* vdarray)
size_t i = 0; size_t i = 0;
char text[100] = {0,}; char text[100] = {0,};
Assert(vdarray); Assert(vdarray);
printf("%s: vdarray.n=%lu\n", title, (unsigned long)vdarray->n); printf("%s: vdarray.n=%zu\n", title, vdarray->n);
for (i = 0; i < vdarray->n; i++) { for (i = 0; i < vdarray->n; i++) {
snprintf(text, sizeof(text), " vdarray->v[%lu]", (unsigned long)i); snprintf(text, sizeof(text), " vdarray->v[%zu]", i);
grib_darray_print(text, vdarray->v[i]); grib_darray_print(text, vdarray->v[i]);
} }
printf("\n"); printf("\n");

View File

@ -23,9 +23,9 @@ void grib_viarray_print(const char* title, const grib_viarray* viarray)
char text[100] = {0,}; char text[100] = {0,};
const size_t textLen = sizeof(text); const size_t textLen = sizeof(text);
Assert(viarray); Assert(viarray);
printf("%s: viarray.n=%lu\n", title, (unsigned long)viarray->n); printf("%s: viarray.n=%zu\n", title, viarray->n);
for (i = 0; i < viarray->n; i++) { for (i = 0; i < viarray->n; i++) {
snprintf(text, textLen, " viarray->v[%lu]", (unsigned long)i); snprintf(text, textLen, " viarray->v[%zu]", i);
grib_iarray_print(text, viarray->v[i]); grib_iarray_print(text, viarray->v[i]);
} }
printf("\n"); printf("\n");

View File

@ -559,7 +559,6 @@ int grib_tool_finalise_action(grib_runtime_options* options)
while ((global_handle = codes_bufr_handle_new_from_file(c, options->infile_extra->file, &err))) { while ((global_handle = codes_bufr_handle_new_from_file(c, options->infile_extra->file, &err))) {
morein1++; morein1++;
if (global_handle)
grib_handle_delete(global_handle); grib_handle_delete(global_handle);
} }
@ -889,7 +888,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) {
printInfo(handle1); printInfo(handle1);
printf("Different size for \"%s\" [%ld] [%ld]\n", name, (long)len1, (long)len2); printf("Different size for \"%s\" [%zu] [%zu]\n", name, len1, len2);
err1 = GRIB_INTERNAL_ERROR; err1 = GRIB_INTERNAL_ERROR;
save_error(c, name); save_error(c, name);
} }
@ -907,7 +906,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
if (len1 == 1) if (len1 == 1)
printf("string [%s]: [%s] != [%s]\n", name, *svals1, *svals2); printf("string [%s]: [%s] != [%s]\n", name, *svals1, *svals2);
else else
printf("string [%s] %d out of %ld different\n", name, countdiff, (long)len1); printf("string [%s] %d out of %zu different\n", name, countdiff, len1);
} }
} }
for (ii = 0; ii < len1; ++ii) grib_context_free(c, svals1[ii]); for (ii = 0; ii < len1; ++ii) grib_context_free(c, svals1[ii]);
@ -945,7 +944,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) {
printInfo(handle1); printInfo(handle1);
printf("Different size for \"%s\" [%ld] [%ld]\n", name, (long)len1, (long)len2); printf("Different size for \"%s\" [%zu] [%zu]\n", name, len1, len2);
err1 = GRIB_INTERNAL_ERROR; err1 = GRIB_INTERNAL_ERROR;
save_error(c, name); save_error(c, name);
} }
@ -963,7 +962,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
if (len1 == 1) if (len1 == 1)
printf("long [%s]: [%ld] != [%ld]\n", name, *lval1, *lval2); printf("long [%s]: [%ld] != [%ld]\n", name, *lval1, *lval2);
else else
printf("long [%s] %d out of %ld different\n", name, countdiff, (long)len1); printf("long [%s] %d out of %zu different\n", name, countdiff, len1);
} }
} }
@ -1030,7 +1029,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) {
printInfo(handle1); printInfo(handle1);
printf("Different size for \"%s\" [%ld] [%ld]\n", name, (long)len1, (long)len2); printf("Different size for \"%s\" [%zu] [%zu]\n", name, len1, len2);
save_error(c, name); save_error(c, name);
} }
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) {
@ -1074,7 +1073,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
printInfo(handle1); printInfo(handle1);
save_error(c, name); save_error(c, name);
if (len1 > 1) { if (len1 > 1) {
printf("double [%s]: %d out of %ld different\n", name, countdiff, (long)len1); printf("double [%s]: %d out of %zu different\n", name, countdiff, len1);
if (dval1[imaxdiff] != GRIB_MISSING_DOUBLE && dval2[imaxdiff] != GRIB_MISSING_DOUBLE) { if (dval1[imaxdiff] != GRIB_MISSING_DOUBLE && dval2[imaxdiff] != GRIB_MISSING_DOUBLE) {
if (compareAbsolute) if (compareAbsolute)
printf(" max"); printf(" max");

View File

@ -84,7 +84,7 @@ static int split_file(FILE* in, const char* filename, const int nchunks, unsigne
msg_size += size; msg_size += size;
if (read_size > chunk_size && msg_size < insize) { if (read_size > chunk_size && msg_size < insize) {
if (verbose) if (verbose)
printf("Wrote output file %s (%lu msgs)\n", ofilename, (unsigned long)num_msg); printf("Wrote output file %s (%zu msgs)\n", ofilename, num_msg);
fclose(out); fclose(out);
i++; i++;
/* Start writing to the next file */ /* Start writing to the next file */
@ -103,7 +103,7 @@ static int split_file(FILE* in, const char* filename, const int nchunks, unsigne
} }
} }
if (verbose) if (verbose)
printf("Wrote output file %s (%lu msgs)\n", ofilename, (unsigned long)num_msg - 1); printf("Wrote output file %s (%zu msgs)\n", ofilename, num_msg - 1);
fclose(out); fclose(out);
free(ofilename); free(ofilename);

View File

@ -840,7 +840,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) {
printInfo(h1); printInfo(h1);
printf("Different size for \"%s\" [%ld] [%ld]\n", name, (long)len1, (long)len2); printf("Different size for \"%s\" [%zu] [%zu]\n", name, len1, len2);
save_error(c, name); save_error(c, name);
} }
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) {
@ -865,7 +865,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
printf("\n"); printf("\n");
} }
else { else {
printf("long [%s] %d out of %ld different\n", name, countdiff, (long)len1); printf("long [%s] %d out of %zu different\n", name, countdiff, len1);
} }
} }
} }
@ -962,7 +962,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 != len2) {
printInfo(h1); printInfo(h1);
printf("Different size for \"%s\" [%ld] [%ld]\n", name, (long)len1, (long)len2); printf("Different size for \"%s\" [%zu] [%zu]\n", name, len1, len2);
save_error(c, name); save_error(c, name);
} }
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) { if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) {
@ -1012,7 +1012,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
printInfo(h1); printInfo(h1);
save_error(c, name); save_error(c, name);
if (len1 > 1) { if (len1 > 1) {
printf("double [%s]: %d out of %ld different\n", name, countdiff, (long)len1); printf("double [%s]: %d out of %zu different\n", name, countdiff, len1);
if (compareAbsolute) if (compareAbsolute)
printf(" max"); printf(" max");
printf(" absolute diff. = %.16e,", fabs(dval1[imaxdiff] - dval2[imaxdiff])); printf(" absolute diff. = %.16e,", fabs(dval1[imaxdiff] - dval2[imaxdiff]));

View File

@ -332,7 +332,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
if (!global_handle || err != GRIB_SUCCESS) { if (!global_handle || err != GRIB_SUCCESS) {
morein1++; morein1++;
if (global_handle)
grib_handle_delete(global_handle); grib_handle_delete(global_handle);
return 0; return 0;
} }