[gnome-control-center/benzea/display-more-error-handling: 1/2] display: Add failure returns into CcDisplayConfig
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/benzea/display-more-error-handling: 1/2] display: Add failure returns into CcDisplayConfig
- Date: Wed, 3 Jul 2019 08:04:47 +0000 (UTC)
commit cebbc42a14c08c2efdc31d5a85af1360e3984532
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 2615461ea..891125409 100644
--- a/panels/display/cc-display-config-dbus.c
+++ b/panels/display/cc-display-config-dbus.c
@@ -1052,6 +1052,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 3bed67a49..c84028e11 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_propagate_error (error,
+ g_error_new_literal (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,17 +576,20 @@ 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]