MT#55283 fix config parsing strategy

Looks like glib at some point started resetting an existing string array
that a config option is pointing to if that config option isn't present
at all. Work around this by explicitly resetting the pointed-to variable
to NULL, and then fixing up the contents on the second pass: either use
the setting from the config file or the one from the command line, and
free the other one.

Change-Id: Ida89d71e54fc30b4cce3277107e2185737f54a51
pull/1759/head
Richard Fuchs 2 years ago
parent 4f6f5fdf4e
commit 48f98032d4

@ -286,6 +286,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
e->description = NULL;
CONF_OPTION_GLUE(string, char *);
e->description = (void *) *s;
*s = NULL;
break;
}
@ -296,6 +297,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
e->description = NULL;
CONF_OPTION_GLUE(string_list, char **, NULL);
e->description = (void *) *s;
*s = NULL;
break;
}
@ -319,7 +321,9 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
case G_OPTION_ARG_STRING:
case G_OPTION_ARG_FILENAME: {
char **s = e->arg_data;
if (*s != e->description)
if (!*s && e->description)
*s = (char *) e->description;
else if (*s != e->description)
g_free((void *) e->description);
if (*s) {
size_t len = strlen(*s);
@ -331,7 +335,9 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
case G_OPTION_ARG_STRING_ARRAY: {
char ***s = e->arg_data;
if (*s != (void *) e->description)
if (!*s && e->description)
*s = (char **) e->description;
else if (*s != (void *) e->description)
g_strfreev((void *) e->description);
if (*s) {
for (int i = 0; (*s)[i]; i++) {

Loading…
Cancel
Save