[gnome-control-center/benzea/display-more-error-handling: 24/25] display: Add failure returns into CcDisplayConfig



commit 561ac849d733545f73f2d3fd9ee8c530f3174129
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Jul 3 09:52:42 2019 +0200

    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.

 panels/display/cc-display-config-dbus.c |  3 +++
 panels/display/cc-display-config.c      | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
---
diff --git a/panels/display/cc-display-config-dbus.c b/panels/display/cc-display-config-dbus.c
index 7f342775a..3a40ac783 100644
--- a/panels/display/cc-display-config-dbus.c
+++ b/panels/display/cc-display-config-dbus.c
@@ -1055,6 +1055,9 @@ cc_display_config_dbus_equal (CcDisplayConfig *pself,
   CcDisplayConfigDBus *other = CC_DISPLAY_CONFIG_DBUS (pother);
   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 (other);
 
diff --git a/panels/display/cc-display-config.c b/panels/display/cc-display-config.c
index 4eb100b1e..a36f82989 100644
--- a/panels/display/cc-display-config.c
+++ b/panels/display/cc-display-config.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include <gio/gio.h>
 #include <math.h>
 #include "cc-display-config.h"
 
@@ -480,12 +481,14 @@ cc_display_config_class_init (CcDisplayConfigClass *klass)
 GList *
 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);
 }
 
 GList *
 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;
 }
 
@@ -496,6 +499,8 @@ cc_display_config_count_useful_monitors (CcDisplayConfig *self)
   GList *outputs, *l;
   guint count = 0;
 
+  g_return_val_if_fail (CC_IS_DISPLAY_CONFIG (self), 0);
+
   outputs = priv->ui_sorted_monitors;
   for (l = outputs; l != NULL; l = l->next)
     {
@@ -512,6 +517,7 @@ cc_display_config_count_useful_monitors (CcDisplayConfig *self)
 gboolean
 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);
 }
 
@@ -521,6 +527,8 @@ cc_display_config_set_mode_on_all_outputs (CcDisplayConfig *config,
 {
   GList *outputs, *l;
 
+  g_return_if_fail (CC_IS_DISPLAY_CONFIG (config));
+
   outputs = cc_display_config_get_monitors (config);
   for (l = outputs; l; l = l->next)
     {
@@ -534,6 +542,9 @@ gboolean
 cc_display_config_equal (CcDisplayConfig *self,
                          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);
 }
 
@@ -541,12 +552,23 @@ gboolean
 cc_display_config_apply (CcDisplayConfig *self,
                          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);
 }
 
 gboolean
 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);
 }
 
@@ -554,18 +576,21 @@ void
 cc_display_config_set_cloning (CcDisplayConfig *self,
                                gboolean clone)
 {
+  g_return_if_fail (CC_IS_DISPLAY_CONFIG (self));
   return CC_DISPLAY_CONFIG_GET_CLASS (self)->set_cloning (self, clone);
 }
 
 GList *
 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);
 }
 
 gboolean
 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);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]