From 17cf9edcd4042c100f440ff852794d59eb3a7cd7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 30 Nov 2021 13:27:22 +0000 Subject: [PATCH] Examples: cppcheck warnings --- examples/C/grib_precision.c | 1 + examples/C/grib_set_bitmap.c | 1 + examples/C/grib_set_keys.c | 1 + examples/C/grib_set_missing.c | 3 ++- examples/C/grib_set_pv.c | 1 + examples/C/large_grib1.c | 8 +++++--- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/C/grib_precision.c b/examples/C/grib_precision.c index 4b197493c..ae39318b2 100644 --- a/examples/C/grib_precision.c +++ b/examples/C/grib_precision.c @@ -62,6 +62,7 @@ int main(int argc, char** argv) h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { fprintf(stderr, "Error: unable to create handle from file %s\n", infile); + fclose(out); return 1; } diff --git a/examples/C/grib_set_bitmap.c b/examples/C/grib_set_bitmap.c index 5a29da19e..7bf4edf24 100644 --- a/examples/C/grib_set_bitmap.c +++ b/examples/C/grib_set_bitmap.c @@ -52,6 +52,7 @@ int main(int argc, char** argv) h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { fprintf(stderr, "Error: unable to create handle from file %s\n", infile); + fclose(out); return 1; } diff --git a/examples/C/grib_set_keys.c b/examples/C/grib_set_keys.c index 7c87f4e9f..feea6731a 100644 --- a/examples/C/grib_set_keys.c +++ b/examples/C/grib_set_keys.c @@ -53,6 +53,7 @@ int main(int argc, char** argv) h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { fprintf(stderr, "Error: unable to create handle from file %s\n", infile); + fclose(out); return 1; } diff --git a/examples/C/grib_set_missing.c b/examples/C/grib_set_missing.c index 74621a7a7..543bb1db3 100644 --- a/examples/C/grib_set_missing.c +++ b/examples/C/grib_set_missing.c @@ -47,10 +47,11 @@ int main(int argc, char** argv) return 1; } - /* create a new handle from a message in a file */ + /* create a new GRIB handle from a message in a file */ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { fprintf(stderr, "Error: unable to create handle from file %s\n", infile); + fclose(out); return 1; } diff --git a/examples/C/grib_set_pv.c b/examples/C/grib_set_pv.c index 2aef5e53d..7ca4c32fe 100644 --- a/examples/C/grib_set_pv.c +++ b/examples/C/grib_set_pv.c @@ -61,6 +61,7 @@ int main(int argc, char** argv) h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { fprintf(stderr, "Error: unable to create handle from file %s\n", infile); + fclose(out); return 1; } diff --git a/examples/C/large_grib1.c b/examples/C/large_grib1.c index 042f7a32a..0b4b21620 100644 --- a/examples/C/large_grib1.c +++ b/examples/C/large_grib1.c @@ -17,15 +17,17 @@ int main() { const int ni = 2880; const int nj = 2880; + size_t numbytes = 0; double* values; int i = 0; codes_handle* h = NULL; const char* filename = "bigfile.grib"; - values = (double*)malloc(ni * nj * sizeof(double)); + numbytes = ni * nj * sizeof(double); + values = (double*)malloc(numbytes); if (!values) { - printf("Malloc failed - requested %lu bytes\n", ni * nj * sizeof(double)); - exit(1); + printf("Malloc failed - requested %lu bytes\n", (unsigned long)numbytes); + return 1; } for (i = 0; i < ni * nj; i++) {