From 4b08450a0dd65afcd858055592f2b78394871b91 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 20:37:10 +0000 Subject: [PATCH] Const correctness and cppcheck warnings --- src/action_class_hash_array.cc | 7 ++++--- src/action_class_noop.cc | 5 ++--- src/action_class_set.cc | 4 ++-- src/action_class_template.cc | 2 +- src/action_class_transient_darray.cc | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/action_class_hash_array.cc b/src/action_class_hash_array.cc index 609e763f2..430fdd92a 100644 --- a/src/action_class_hash_array.cc +++ b/src/action_class_hash_array.cc @@ -199,8 +199,9 @@ static void destroy(grib_context* context, grib_action* act) { grib_action_hash_array* self = (grib_action_hash_array*)act; - grib_hash_array_value* v = self->hash_array; - Assert(!v); // not implemented + // This is currently unset. So assert that it is NULL + const grib_hash_array_value* v = self->hash_array; + Assert(v == NULL); // if (v) // grib_trie_delete(v->index); // while (v) { @@ -335,6 +336,6 @@ grib_hash_array_value* get_hash_array(grib_handle* h, grib_action* a) const char* get_hash_array_full_path(grib_action* a) { - grib_action_hash_array* self = (grib_action_hash_array*)a; + const grib_action_hash_array* self = (grib_action_hash_array*)a; return self->full_path; } diff --git a/src/action_class_noop.cc b/src/action_class_noop.cc index a898da06a..aa5196a46 100644 --- a/src/action_class_noop.cc +++ b/src/action_class_noop.cc @@ -73,16 +73,15 @@ grib_action* grib_action_create_noop(grib_context* context, const char* fname) { char buf[1024]; - grib_action_noop* a; grib_action_class* c = grib_action_class_noop; grib_action* act = (grib_action*)grib_context_malloc_clear_persistent(context, c->size); act->op = grib_context_strdup_persistent(context, "section"); act->cclass = c; - a = (grib_action_noop*)act; + grib_action_noop* a = (grib_action_noop*)act; act->context = context; - snprintf(buf, 1024, "_noop%p", (void*)a); + snprintf(buf, sizeof(buf), "_noop%p", (void*)a); act->name = grib_context_strdup_persistent(context, buf); diff --git a/src/action_class_set.cc b/src/action_class_set.cc index 1068181d5..fee2ca406 100644 --- a/src/action_class_set.cc +++ b/src/action_class_set.cc @@ -114,8 +114,8 @@ static int execute(grib_action* a, grib_handle* h) static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_set* self = (grib_action_set*)act; + int i = 0; + const grib_action_set* self = (grib_action_set*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); diff --git a/src/action_class_template.cc b/src/action_class_template.cc index 33a753513..79fd2aeaf 100644 --- a/src/action_class_template.cc +++ b/src/action_class_template.cc @@ -117,7 +117,7 @@ static void dump(grib_action* act, FILE* f, int lvl) static grib_action* get_empty_template(grib_context* c, int* err) { char fname[] = "empty_template.def"; - char* path = grib_context_full_defs_path(c, fname); + const char* path = grib_context_full_defs_path(c, fname); if (path) { *err = GRIB_SUCCESS; return grib_parse_file(c, path); diff --git a/src/action_class_transient_darray.cc b/src/action_class_transient_darray.cc index 9990beb41..673f83502 100644 --- a/src/action_class_transient_darray.cc +++ b/src/action_class_transient_darray.cc @@ -122,8 +122,8 @@ static int execute(grib_action* act, grib_handle* h) static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_transient_darray* self = (grib_action_transient_darray*)act; + int i = 0; + const grib_action_transient_darray* self = (grib_action_transient_darray*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name);