GOptionContext: Don't crash without main group
authorMatthias Clasen <mclasen@redhat.com>
Mon, 27 Jul 2015 11:52:27 +0000 (07:52 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 27 Jul 2015 11:53:40 +0000 (07:53 -0400)
This was introduced in 126c685f4aa and caused e.g. gdbus
to crash when called without arguments.

https://bugzilla.gnome.org/show_bug.cgi?id=752210

glib/goption.c

index 8a1848d..0464c2e 100644 (file)
@@ -854,9 +854,9 @@ g_option_context_get_help (GOptionContext *context,
         }
     }
 
-  g_string_append_printf (string, "%s\n  %s", _("Usage:"), g_get_prgname());
+  g_string_append_printf (string, "%s\n  %s", _("Usage:"), g_get_prgname ());
   if (context->help_enabled ||
-      context->main_group->n_entries > 0 ||
+      (context->main_group && context->main_group->n_entries > 0) ||
       context->groups != NULL)
     g_string_append_printf (string, " %s", _("[OPTION...]"));