From d124b9bff0c7ea561b0609a03025cb4860918548 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 29 Jan 2022 18:17:43 +0100 Subject: [PATCH] [option] union of const and non-const char * in option --- src/config/options.c | 4 ++-- src/config/options.h | 7 +++++-- src/mime/dialogs.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/config/options.c b/src/config/options.c index 5773fc993..df41821d0 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -232,7 +232,7 @@ get_opt_rec(struct option *tree, const char *name_) mem_free(aname); return NULL; } - mem_free_set(&option->name, stracpy(name)); + mem_free_set(&option->aname, stracpy(name)); add_opt_rec(tree, "", option); @@ -601,7 +601,7 @@ done_option(struct option *option) done_listbox_item(&option_browser, option->box_item); if (option->flags & OPT_ALLOC) { - mem_free_if(option->name); + mem_free_if(option->aname); mem_free(option); } else if (!option->capt) { /* We are probably dealing with a built-in autocreated option diff --git a/src/config/options.h b/src/config/options.h index 7f05f8ecf..5e07be318 100644 --- a/src/config/options.h +++ b/src/config/options.h @@ -193,7 +193,10 @@ typedef int (*change_hook_T)(struct session *session, struct option *current, struct option { OBJECT_HEAD(struct option); - char *name; + union { + const char *name; + char *aname; + }; option_flags_T flags; enum option_type type; long min, max; @@ -216,7 +219,7 @@ struct option { * with ::INIT_OPT_INT or a similar macro. * @relates option */ #define INIT_OPTION(name, flags, type, min, max, value, desc, capt) \ - { NULL_LIST_HEAD, INIT_OBJECT("option"), name, flags, type, min, max, { (LIST_OF(struct option) *) (value) }, desc, capt } + { NULL_LIST_HEAD, INIT_OBJECT("option"), {name}, flags, type, min, max, { (LIST_OF(struct option) *) (value) }, desc, capt } extern struct option *config_options; extern struct option *cmdline_options; diff --git a/src/mime/dialogs.c b/src/mime/dialogs.c index f70e58248..87483bf9e 100644 --- a/src/mime/dialogs.c +++ b/src/mime/dialogs.c @@ -159,8 +159,8 @@ menu_list_ext(struct terminal *term, void *fn_, void *xxx) if (!strcmp(opt->name, "_template_")) continue; if (!init_string(&translated) - || !add_real_optname_to_string(&translated, opt->name, - strlen(opt->name))) { + || !add_real_optname_to_string(&translated, opt->aname, + strlen(opt->aname))) { done_string(&translated); continue; }