From 9d07ddb3ab4829b5f4cc47b0512ef97303bb5a4a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 2 Jun 2022 19:29:29 +0100 Subject: [PATCH] C++: Const correctness --- tools/bufr_dump.c | 12 ++++++------ tools/grib_dump.c | 8 ++++---- tools/grib_index_build.c | 4 ++-- tools/grib_ls.c | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/bufr_dump.c b/tools/bufr_dump.c index f4421a957..af4e88111 100644 --- a/tools/bufr_dump.c +++ b/tools/bufr_dump.c @@ -104,7 +104,7 @@ int grib_tool_init(grib_runtime_options* options) { int opt = grib_options_on("C") + grib_options_on("O"); - options->dump_mode = "default"; + options->dump_mode = (char*)"default"; options->strict = 1; /* Must set here as bufr_dump has its own -S option */ if (opt > 1) { @@ -113,7 +113,7 @@ int grib_tool_init(grib_runtime_options* options) } if (grib_options_on("j:")) { - options->dump_mode = "json"; + options->dump_mode = (char*)"json"; json_option = grib_options_get_option("j:"); if (strlen(json_option) > 1 || (json_option[0] != 's' && json_option[0] != 'f' && json_option[0] != 'a')) { printf("%s: Invalid JSON option %s\n", tool_name, json_option); @@ -123,13 +123,13 @@ int grib_tool_init(grib_runtime_options* options) } if (grib_options_on("O")) { - options->dump_mode = "wmo"; + options->dump_mode = (char*)"wmo"; json = 0; options->dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY; } if (grib_options_on("p")) { - options->dump_mode = "bufr_simple"; + options->dump_mode = (char*)"bufr_simple"; json = 0; } @@ -240,7 +240,7 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi return 0; } -static char* get_dumper_name(grib_runtime_options* options) +static const char* get_dumper_name(grib_runtime_options* options) { if (grib_options_on("E:")) { /* Dumper for ENCODING */ @@ -306,7 +306,7 @@ static void bufr_dump_descriptors(grib_handle* h) char** array_names = NULL; char** array_abbrevs = NULL; char** array_units = NULL; - char* the_key = "expandedDescriptors"; + const char* the_key = "expandedDescriptors"; GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_desc), 0); array_descriptors = (long*)malloc(size_desc * sizeof(long)); diff --git a/tools/grib_dump.c b/tools/grib_dump.c index 138acbb91..a8a5839f4 100644 --- a/tools/grib_dump.c +++ b/tools/grib_dump.c @@ -66,7 +66,7 @@ int grib_tool_init(grib_runtime_options* options) { int opt = grib_options_on("C") + grib_options_on("O") + grib_options_on("D") + grib_options_on("j"); - options->dump_mode = "default"; + options->dump_mode = (char*)"default"; if (opt > 1) { fprintf(stderr, "%s: simultaneous j/O/D options not allowed\n", tool_name); @@ -74,7 +74,7 @@ int grib_tool_init(grib_runtime_options* options) } if (grib_options_on("j")) { - options->dump_mode = "json"; + options->dump_mode = (char*)"json"; json = 1; } @@ -89,12 +89,12 @@ int grib_tool_init(grib_runtime_options* options) */ if (grib_options_on("O")) { - options->dump_mode = "wmo"; + options->dump_mode = (char*)"wmo"; options->dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY; } if (grib_options_on("D")) { - options->dump_mode = "debug"; + options->dump_mode = (char*)"debug"; options->dump_flags = GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY; } diff --git a/tools/grib_index_build.c b/tools/grib_index_build.c index 24e959fbc..d8c0add78 100644 --- a/tools/grib_index_build.c +++ b/tools/grib_index_build.c @@ -19,8 +19,8 @@ const char* tool_description = "Build an index file for a set of input GRIB file const char* tool_name = "grib_index_build"; const char* tool_usage = "[options] grib_file grib_file ... "; static grib_index* idx = NULL; -static char* keys; -static char* default_keys = "mars"; +static const char* keys; +static const char* default_keys = "mars"; grib_option grib_options[] = { /* {id, args, help}, on, command_line, value */ diff --git a/tools/grib_ls.c b/tools/grib_ls.c index b6d4da1f4..e6690b285 100644 --- a/tools/grib_ls.c +++ b/tools/grib_ls.c @@ -47,7 +47,7 @@ const char* tool_description = "some keys.\n\tIt does not fail when a key is not found."; const char* tool_name = "grib_ls"; const char* tool_usage = "[options] grib_file grib_file ..."; -static char* new_handle = ""; +static const char* new_handle = ""; int grib_options_count = sizeof(grib_options) / sizeof(grib_option); static double lat = 0; @@ -219,7 +219,7 @@ static void print_key_values(grib_runtime_options* options, grib_handle* h) { int i; int ret = 0; - char* s = "\"keys\" : {"; + const char* s = "\"keys\" : {"; double dvalue = 0; long lvalue = 0; char value[MAX_STRING_LEN]; @@ -322,7 +322,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) } if (json_latlon) { - char* s = "\n[\n"; + const char* s = "\n[\n"; double missingValue = 9999; char value[MAX_STRING_LEN]; size_t len = MAX_STRING_LEN;