Fix compiler warning about uninitialized variable in giomodule

It could've never been uninitialized in this code but the code flow is
not obvious to the compiler. Initialize it to NULL and for clarity also
add an assertion that it is not NULL anymore on usage.

In file included from ../glib/glib.h:62,
                 from ../gobject/gbinding.h:28,
                 from ../glib/glib-object.h:23,
                 from ../gio/gioenums.h:28,
                 from ../gio/giotypes.h:28,
                 from ../gio/giomodule.h:28,
                 from ../gio/giomodule.c:25:
../gio/giomodule.c: In function ‘_g_io_module_get_default’:
../glib/gmessages.h:343:25: warning: ‘extension’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 #define g_debug(...)    g_log (G_LOG_DOMAIN,         \
                         ^~~~~
../gio/giomodule.c:912:17: note: ‘extension’ was declared here
   GIOExtension *extension, *preferred;
                 ^~~~~~~~~
This commit is contained in:
Sebastian Dröge 2019-01-24 16:35:13 +02:00
parent 72329ea303
commit b4a5157f95

View File

@ -909,7 +909,7 @@ _g_io_module_get_default (const gchar *extension_point,
const char *use_this;
GList *l;
GIOExtensionPoint *ep;
GIOExtension *extension, *preferred;
GIOExtension *extension = NULL, *preferred;
gpointer impl;
g_rec_mutex_lock (&default_modules_lock);
@ -986,9 +986,12 @@ _g_io_module_get_default (const gchar *extension_point,
g_rec_mutex_unlock (&default_modules_lock);
if (impl != NULL)
g_debug ("%s: Found default implementation %s (%s) for %s",
G_STRFUNC, g_io_extension_get_name (extension),
G_OBJECT_TYPE_NAME (impl), extension_point);
{
g_assert (extension != NULL);
g_debug ("%s: Found default implementation %s (%s) for %s",
G_STRFUNC, g_io_extension_get_name (extension),
G_OBJECT_TYPE_NAME (impl), extension_point);
}
else
g_debug ("%s: Failed to find default implementation for %s",
G_STRFUNC, extension_point);