From dbc044d8287a044d26cc38c7751f5f8097a9d5e3 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 30 Jun 2022 16:52:04 +0100 Subject: [PATCH] Tools: cppcheck warnings --- tools/grib_2_request.c | 74 --------------------------------------- tools/grib_compare.c | 7 ++-- tools/grib_dump.c | 2 +- tools/grib_nearest_land.c | 18 +++++----- 4 files changed, 14 insertions(+), 87 deletions(-) delete mode 100644 tools/grib_2_request.c diff --git a/tools/grib_2_request.c b/tools/grib_2_request.c deleted file mode 100644 index 81cbc10aa..000000000 --- a/tools/grib_2_request.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * (C) Copyright 2005- ECMWF. - * - * This software is licensed under the terms of the Apache Licence Version 2.0 - * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. - * - * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by - * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. - */ - -#include "config.h" -#include -#include - -#include "grib_api_internal.h" - - -int main(int argc, char* argv[]) -{ - grib_handle* h = NULL; - FILE* f = NULL; - int i = 0; - int err = 0; - char* mode = "file"; - char name[80]; - char value[80]; - - - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - mode = argv[i] + 1; - continue; - } - - f = fopen(argv[i], "r"); - if (!f) { - perror(argv[i]); - exit(1); - } - - while ((h = grib_handle_new_from_file(0, f, &err)) != NULL) { - grib_keys_iterator* ks = grib_keys_iterator_new(h, GRIB_KEYS_ITERATOR_ALL_KEYS, "mars"); - while (grib_keys_iterator_next(ks)) { - size_t len = sizeof(value); - char tmp[100]; - - strcpy(name, grib_keys_iterator_get_name(ks)); - - sprintf(tmp, "mars.%s", name); - - if ((err = grib_keys_iterator_get_string(ks, value, &len)) != GRIB_SUCCESS) - /* if(err = grib_get_string(h,tmp,value,&len)) */ - { - fprintf(stderr, "Cannot get %s as string %d (%s)\n", name, err, - grib_get_error_message(err)); - exit(err); - } - - printf("%s=%s\n", name, value); - } - grib_keys_iterator_delete(ks); - printf("\n"); - - - grib_handle_delete(h); - } - fclose(f); - if (err) { - fprintf(stderr, "%s\n", grib_get_error_message(err)); - exit(1); - } - } - return 0; -} diff --git a/tools/grib_compare.c b/tools/grib_compare.c index a547cb22c..cb4f8ab90 100644 --- a/tools/grib_compare.c +++ b/tools/grib_compare.c @@ -189,7 +189,7 @@ int grib_tool_before_getopt(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options) { - int ret = 0, i = 0; + int ret = 0; int nfiles = 1; const char orderby[] = "md5Headers"; grib_context* context = grib_context_get_default(); @@ -240,6 +240,7 @@ int grib_tool_init(grib_runtime_options* options) } if (grib_options_on("b:")) { + int i; grib_string_list* next = 0; blocklist = (grib_string_list*)grib_context_malloc_clear(context, sizeof(grib_string_list)); blocklist->value = grib_context_strdup(context, options->set_values[0].name); @@ -281,6 +282,7 @@ int grib_tool_init(grib_runtime_options* options) global_tolerance = 0; compare_double = &compare_double_absolute; if (grib_options_on("R:")) { + int i; global_tolerance = 0; for (i = 0; i < options->tolerance_count; i++) { if (!strcmp((options->tolerance[i]).name, "all")) { @@ -533,8 +535,7 @@ int grib_tool_finalise_action(grib_runtime_options* options) while ((handle1 = grib_handle_new_from_file(c, options->infile_extra->file, &err))) { morein1++; - if (handle1) - grib_handle_delete(handle1); + grib_handle_delete(handle1); } error += morein1 + morein2; diff --git a/tools/grib_dump.c b/tools/grib_dump.c index a8a5839f4..1659a354a 100644 --- a/tools/grib_dump.c +++ b/tools/grib_dump.c @@ -202,7 +202,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) if (!first_handle && options->handle_count > 1) { fprintf(stdout, ",\n"); } - if (json && first_handle) { + if (first_handle) { fprintf(stdout, "{ \"messages\" : [\n"); first_handle = 0; } diff --git a/tools/grib_nearest_land.c b/tools/grib_nearest_land.c index bb6039b22..b6bcfb54d 100644 --- a/tools/grib_nearest_land.c +++ b/tools/grib_nearest_land.c @@ -32,7 +32,7 @@ int main(int argc, char** argv) char* fname = 0; float lat, lon; double *vlat, *vlon; - int npoints = 0, i = 0, n = 0; + long npoints = 0, i = 0, n = 0; grib_handle* h; double *outlats, *outlons, *values, *lsm_values, *distances; size_t* indexes; @@ -53,42 +53,42 @@ int main(int argc, char** argv) vlat = (double*)malloc(npoints * sizeof(double)); if (!vlat) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } vlon = (double*)malloc(npoints * sizeof(double)); if (!vlon) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } outlats = (double*)malloc(npoints * sizeof(double)); if (!outlats) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } outlons = (double*)malloc(npoints * sizeof(double)); if (!outlons) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } values = (double*)malloc(npoints * sizeof(double)); if (!values) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } lsm_values = (double*)malloc(npoints * sizeof(double)); if (!lsm_values) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } distances = (double*)malloc(npoints * sizeof(double)); if (!distances) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); } indexes = (size_t*)malloc(npoints * sizeof(double)); if (!indexes) { - printf("unable to allocate %d bytes\n", npoints * sizeof(double)); + printf("unable to allocate %lu bytes\n", npoints * sizeof(double)); exit(1); }