gtk: Fix more ubsan warnings

Most of these are calling a get_instance_private() function before
checking that the object isn't NULL.
This commit is contained in:
Matthias Clasen 2024-04-21 21:59:48 -04:00
parent 815df9a76a
commit 246eb8ea25
5 changed files with 20 additions and 13 deletions

View File

@ -990,11 +990,13 @@ GtkActionMuxer *
gtk_application_get_parent_muxer_for_window (GtkWindow *window)
{
GtkApplication *application = gtk_window_get_application (window);
GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
GtkApplicationPrivate *priv;
if (!application)
return NULL;
priv = gtk_application_get_instance_private (application);
return priv->muxer;
}

View File

@ -1006,7 +1006,7 @@ gtk_check_button_set_group (GtkCheckButton *self,
GtkCheckButton *group)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
GtkCheckButtonPrivate *group_priv = gtk_check_button_get_instance_private (group);
GtkCheckButtonPrivate *group_priv;
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
g_return_if_fail (self != group);
@ -1037,6 +1037,8 @@ gtk_check_button_set_group (GtkCheckButton *self,
if (priv->group_next == group)
return;
group_priv = gtk_check_button_get_instance_private (group);
priv->group_prev = NULL;
if (group_priv->group_prev)
{

View File

@ -637,7 +637,7 @@ resource_is_pixdata (const char *resource_path)
if (data_size < sizeof(guint32))
goto out;
magic = (stream[0] << 24) + (stream[1] << 16) + (stream[2] << 8) + stream[3];
magic = (((guint32)(stream[0])) << 24) | (((guint32)(stream[1])) << 16) | (((guint32)(stream[2])) << 8) | (guint32)(stream[3]);
if (magic == GDK_PIXBUF_MAGIC_NUMBER)
ret = TRUE;

View File

@ -511,7 +511,7 @@ gtk_toggle_button_set_group (GtkToggleButton *toggle_button,
GtkToggleButton *group)
{
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
GtkToggleButtonPrivate *group_priv = gtk_toggle_button_get_instance_private (group);
GtkToggleButtonPrivate *group_priv;
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
g_return_if_fail (toggle_button != group);
@ -538,6 +538,8 @@ gtk_toggle_button_set_group (GtkToggleButton *toggle_button,
if (priv->group_next == group)
return;
group_priv = gtk_toggle_button_get_instance_private (group);
priv->group_prev = NULL;
if (group_priv->group_prev)
{

View File

@ -5834,21 +5834,22 @@ gtk_window_is_active (GtkWindow *window)
*/
GtkWindowGroup *
gtk_window_get_group (GtkWindow *window)
{
static GtkWindowGroup *default_group = NULL;
if (window)
{
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
if (window && priv->group)
if (priv->group)
return priv->group;
else
{
static GtkWindowGroup *default_group = NULL;
}
if (!default_group)
default_group = gtk_window_group_new ();
return default_group;
}
}
/**
* gtk_window_has_group: