display: Add failure returns into CcDisplayConfig

This guards against accidental use of NULL pointers so that the panel
will hopefully not crash if new bugs like this are introduced.
This commit is contained in:
Benjamin Berg 2019-07-03 09:52:42 +02:00 committed by Georges Basile Stavracas Neto
parent e1cd43cb48
commit 561ac849d7
2 changed files with 28 additions and 0 deletions

View file

@ -1055,6 +1055,9 @@ cc_display_config_dbus_equal (CcDisplayConfig *pself,
CcDisplayConfigDBus *other = CC_DISPLAY_CONFIG_DBUS (pother); CcDisplayConfigDBus *other = CC_DISPLAY_CONFIG_DBUS (pother);
GList *l; GList *l;
g_return_val_if_fail (pself, FALSE);
g_return_val_if_fail (pother, FALSE);
cc_display_config_dbus_ensure_non_offset_coords (self); cc_display_config_dbus_ensure_non_offset_coords (self);
cc_display_config_dbus_ensure_non_offset_coords (other); cc_display_config_dbus_ensure_non_offset_coords (other);

View file

@ -17,6 +17,7 @@
* *
*/ */
#include <gio/gio.h>
#include <math.h> #include <math.h>
#include "cc-display-config.h" #include "cc-display-config.h"
@ -480,12 +481,14 @@ cc_display_config_class_init (CcDisplayConfigClass *klass)
GList * GList *
cc_display_config_get_monitors (CcDisplayConfig *self) cc_display_config_get_monitors (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_monitors (self); return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_monitors (self);
} }
GList * GList *
cc_display_config_get_ui_sorted_monitors (CcDisplayConfig *self) cc_display_config_get_ui_sorted_monitors (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL);
return CC_DISPLAY_CONFIG_GET_PRIVATE (self)->ui_sorted_monitors; return CC_DISPLAY_CONFIG_GET_PRIVATE (self)->ui_sorted_monitors;
} }
@ -496,6 +499,8 @@ cc_display_config_count_useful_monitors (CcDisplayConfig *self)
GList *outputs, *l; GList *outputs, *l;
guint count = 0; guint count = 0;
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), 0);
outputs = priv->ui_sorted_monitors; outputs = priv->ui_sorted_monitors;
for (l = outputs; l != NULL; l = l->next) for (l = outputs; l != NULL; l = l->next)
{ {
@ -512,6 +517,7 @@ cc_display_config_count_useful_monitors (CcDisplayConfig *self)
gboolean gboolean
cc_display_config_is_applicable (CcDisplayConfig *self) cc_display_config_is_applicable (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_applicable (self); return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_applicable (self);
} }
@ -521,6 +527,8 @@ cc_display_config_set_mode_on_all_outputs (CcDisplayConfig *config,
{ {
GList *outputs, *l; GList *outputs, *l;
g_return_if_fail (CC_IS_DISPLAY_CONFIG (config));
outputs = cc_display_config_get_monitors (config); outputs = cc_display_config_get_monitors (config);
for (l = outputs; l; l = l->next) for (l = outputs; l; l = l->next)
{ {
@ -534,6 +542,9 @@ gboolean
cc_display_config_equal (CcDisplayConfig *self, cc_display_config_equal (CcDisplayConfig *self,
CcDisplayConfig *other) CcDisplayConfig *other)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE);
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (other), FALSE);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->equal (self, other); return CC_DISPLAY_CONFIG_GET_CLASS (self)->equal (self, other);
} }
@ -541,12 +552,23 @@ gboolean
cc_display_config_apply (CcDisplayConfig *self, cc_display_config_apply (CcDisplayConfig *self,
GError **error) GError **error)
{ {
if (!CC_IS_DISPLAY_CONFIG (self))
{
g_warning ("Cannot apply invalid configuration");
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"Cannot apply invalid configuration");
return FALSE;
}
return CC_DISPLAY_CONFIG_GET_CLASS (self)->apply (self, error); return CC_DISPLAY_CONFIG_GET_CLASS (self)->apply (self, error);
} }
gboolean gboolean
cc_display_config_is_cloning (CcDisplayConfig *self) cc_display_config_is_cloning (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_cloning (self); return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_cloning (self);
} }
@ -554,18 +576,21 @@ void
cc_display_config_set_cloning (CcDisplayConfig *self, cc_display_config_set_cloning (CcDisplayConfig *self,
gboolean clone) gboolean clone)
{ {
g_return_if_fail (CC_IS_DISPLAY_CONFIG (self));
return CC_DISPLAY_CONFIG_GET_CLASS (self)->set_cloning (self, clone); return CC_DISPLAY_CONFIG_GET_CLASS (self)->set_cloning (self, clone);
} }
GList * GList *
cc_display_config_get_cloning_modes (CcDisplayConfig *self) cc_display_config_get_cloning_modes (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), NULL);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_cloning_modes (self); return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_cloning_modes (self);
} }
gboolean gboolean
cc_display_config_is_layout_logical (CcDisplayConfig *self) cc_display_config_is_layout_logical (CcDisplayConfig *self)
{ {
g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), FALSE);
return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_layout_logical (self); return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_layout_logical (self);
} }