goption: Treat an empty option context parameter string as NULL

Otherwise the code ends up calling `gettext ("")`, which returns the
current translation’s header. The caller should really have provided a
NULL, parameter string, but the empty string is clear enough.

See
https://gitlab.freedesktop.org/accountsservice/accountsservice/-/merge_requests/56.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-05-01 14:37:30 +01:00
parent 123e8c9bf6
commit 40a64131d1

View File

@ -241,7 +241,7 @@ struct _GOptionContext
{
GList *groups;
gchar *parameter_string;
gchar *parameter_string; /* (nullable) */
gchar *summary;
gchar *description;
@ -364,6 +364,11 @@ g_option_context_new (const gchar *parameter_string)
context = g_new0 (GOptionContext, 1);
/* Clear the empty string to NULL, otherwise we end up calling gettext(""),
* which returns the translation header. */
if (parameter_string != NULL && *parameter_string == '\0')
parameter_string = NULL;
context->parameter_string = g_strdup (parameter_string);
context->strict_posix = FALSE;
context->help_enabled = TRUE;