From f29e6ca366625d85dd8e8ea322992a6a9f231a86 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 30 Jun 2022 10:28:04 +0100 Subject: [PATCH] ECC-1419: C API: codes_fieldset_new_from_files: The 'filenames' argument should be const --- examples/C/grib_nearest.c | 8 ++++---- src/eccodes.c | 2 +- src/eccodes.h | 2 +- src/eccodes_prototypes.h | 2 +- src/grib_api.h | 2 +- src/grib_fieldset.c | 2 +- tests/grib_fieldset.c | 6 +++--- tests/grib_nearest_test.c | 8 ++++---- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/C/grib_nearest.c b/examples/C/grib_nearest.c index a09bb0881..96f31ccd1 100644 --- a/examples/C/grib_nearest.c +++ b/examples/C/grib_nearest.c @@ -48,15 +48,15 @@ int main(int argc, char** argv) double lat = -40, lon = 15; int mode = 0; int count; - char** filenames; + const char** filenames = NULL; codes_nearest* nearest = NULL; if (argc < 2) usage(argv[0]); nfiles = argc - 1; - filenames = (char**)malloc(sizeof(char*) * nfiles); + filenames = (const char**)malloc(sizeof(char*) * nfiles); for (i = 0; i < nfiles; i++) - filenames[i] = (char*)strdup(argv[i + 1]); + filenames[i] = strdup(argv[i + 1]); set = codes_fieldset_new_from_files(0, filenames, nfiles, 0, 0, 0, order_by, &err); CODES_CHECK(err, 0); @@ -91,7 +91,7 @@ int main(int argc, char** argv) if (set) codes_fieldset_delete(set); for (i = 0; i < nfiles; i++) - free(filenames[i]); + free((char*)filenames[i]); free(filenames); return 0; diff --git a/src/eccodes.c b/src/eccodes.c index 526008384..91018e390 100644 --- a/src/eccodes.c +++ b/src/eccodes.c @@ -69,7 +69,7 @@ void codes_check(const char* call, const char* file, int line, int e, const char /* Fieldsets */ /******************************************************************************/ -grib_fieldset* codes_fieldset_new_from_files(grib_context* c, char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err) +grib_fieldset* codes_fieldset_new_from_files(grib_context* c, const char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err) { return grib_fieldset_new_from_files(c, filenames, nfiles, keys, nkeys, where_string, order_by_string, err); } diff --git a/src/eccodes.h b/src/eccodes.h index 08cf54587..62ef04cb5 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -181,7 +181,7 @@ typedef struct grib_util_packing_spec codes_util_packing_spec; typedef struct grib_util_grid_spec codes_util_grid_spec; -codes_fieldset* codes_fieldset_new_from_files(codes_context* c, char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); +codes_fieldset* codes_fieldset_new_from_files(codes_context* c, const char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); void codes_fieldset_delete(codes_fieldset* set); void codes_fieldset_rewind(codes_fieldset* set); diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 7adaacf9a..eb8b3c6ec 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -986,7 +986,7 @@ long grib_date_to_julian(long ddate); /* grib_fieldset.c */ int grib_fieldset_new_column(grib_fieldset* set, int id, char* key, int type); -grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); +grib_fieldset* grib_fieldset_new_from_files(grib_context* c, const char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); int grib_fieldset_apply_where(grib_fieldset* set, const char* where_string); int grib_fieldset_apply_order_by(grib_fieldset* set, const char* order_by_string); void grib_fieldset_delete_order_by(grib_context* c, grib_order_by* order_by); diff --git a/src/grib_api.h b/src/grib_api.h index 44b023c17..0dc80251f 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -235,7 +235,7 @@ typedef struct bufr_descriptor bufr_descriptor; typedef struct bufr_descriptors_array bufr_descriptors_array; typedef struct bufr_descriptors_map_list bufr_descriptors_map_list; -grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); +grib_fieldset* grib_fieldset_new_from_files(grib_context* c, const char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err); void grib_fieldset_delete(grib_fieldset* set); void grib_fieldset_rewind(grib_fieldset* set); int grib_fieldset_apply_order_by(grib_fieldset* set, const char* order_by_string); diff --git a/src/grib_fieldset.c b/src/grib_fieldset.c index 0afa52284..1c84e564c 100644 --- a/src/grib_fieldset.c +++ b/src/grib_fieldset.c @@ -254,7 +254,7 @@ static int grib_fieldset_column_copy_from_handle(grib_handle* h, grib_fieldset* } /* --------------- grib_fieldset functions ------------------*/ -grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[], +grib_fieldset* grib_fieldset_new_from_files(grib_context* c, const char* filenames[], int nfiles, const char** keys, int nkeys, const char* where_string, const char* order_by_string, int* err) { diff --git a/tests/grib_fieldset.c b/tests/grib_fieldset.c index ff476ab45..a6eb38ce7 100644 --- a/tests/grib_fieldset.c +++ b/tests/grib_fieldset.c @@ -23,7 +23,7 @@ int main(int argc, char** argv) { int err = 0; long step; - char** filenames; + const char** filenames = NULL; size_t nkeys, nfiles, i=0; const char* keys[] = { "step:i", "date", "paramId", "levelType" }; grib_fieldset* set = NULL; @@ -40,7 +40,7 @@ int main(int argc, char** argv) order_by = argv[1]; nfiles = argc - 2; - filenames = (char**)malloc(sizeof(char*) * nfiles); + filenames = (const char**)malloc(sizeof(char*) * nfiles); for (i = 0; i < nfiles; i++) filenames[i] = (char*)strdup(argv[i + 2]); @@ -73,7 +73,7 @@ int main(int argc, char** argv) grib_fieldset_delete(set); grib_handle_delete(h); for (i = 0; i < nfiles; i++) - free(filenames[i]); + free((char*)filenames[i]); free(filenames); return 0; diff --git a/tests/grib_nearest_test.c b/tests/grib_nearest_test.c index a20d3fa0e..cf561f13e 100644 --- a/tests/grib_nearest_test.c +++ b/tests/grib_nearest_test.c @@ -50,12 +50,12 @@ int main(int argc, char** argv) double lat = -40, lon = 15; int mode = 0; int count; - char** filenames; + const char** filenames = NULL; codes_nearest* nearest = NULL; if (argc < 2) usage(argv[0]); - filenames = (char**)malloc(sizeof(char*) * max_numfiles); + filenames = (const char**)malloc(sizeof(char*) * max_numfiles); for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-n") == 0) { @@ -64,7 +64,7 @@ int main(int argc, char** argv) else { if (j >= max_numfiles) break; - filenames[j++] = (char*)strdup(argv[i]); + filenames[j++] = strdup(argv[i]); } } nfiles = j; @@ -114,7 +114,7 @@ int main(int argc, char** argv) if (set) codes_fieldset_delete(set); for (i = 0; i < nfiles; ++i) { - free(filenames[i]); + free((char*)filenames[i]); } free(filenames);