[glib: 1/2] goption: Treat an empty option context parameter string as NULL
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] goption: Treat an empty option context parameter string as NULL
- Date: Fri, 8 May 2020 20:26:49 +0000 (UTC)
commit 40a64131d1dfec01ad9adb59eb22d86641bbd027
Author: Philip Withnall <withnall endlessm com>
Date: Fri May 1 14:37:30 2020 +0100
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>
glib/goption.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/glib/goption.c b/glib/goption.c
index b0fb80c94..9f5b977c4 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]