[gnome-settings-daemon] color: Fix critical warning if the user disables the internal LCD screen



commit cab9b069f021980419876949abd41f31dabe48b2
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 3 15:09:15 2011 +0100

    color: Fix critical warning if the user disables the internal LCD screen
    
    Note: this fix also applies to any output we've disabled but left connected.

 plugins/color/gsd-color-manager.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index b963eb5..73cb3f8 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -733,6 +733,10 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
         const gchar *filename;
         cmsHPROFILE lcms_profile = NULL;
 
+        /* invalid size */
+        if (size == 0)
+                goto out;
+
         /* not an actual profile */
         filename = cd_profile_get_filename (profile);
         if (filename == NULL)
@@ -773,6 +777,8 @@ gnome_rr_output_get_gamma_size (GnomeRROutput *output)
         gint len = 0;
 
         crtc = gnome_rr_output_get_crtc (output);
+        if (crtc == NULL)
+                return 0;
         gnome_rr_crtc_get_gamma (crtc,
                                  &len,
                                  NULL, NULL, NULL);
@@ -815,6 +821,15 @@ gcm_session_output_set_gamma (GnomeRROutput *output,
 
         /* send to LUT */
         crtc = gnome_rr_output_get_crtc (output);
+        if (crtc == NULL) {
+                ret = FALSE;
+                g_set_error (error,
+                             GSD_COLOR_MANAGER_ERROR,
+                             GSD_COLOR_MANAGER_ERROR_FAILED,
+                             "failed to get ctrc for %s",
+                             gnome_rr_output_get_name (output));
+                goto out;
+        }
         gnome_rr_crtc_set_gamma (crtc, array->len,
                                  red, green, blue);
 out:
@@ -830,11 +845,19 @@ gcm_session_device_set_gamma (GnomeRROutput *output,
                               GError **error)
 {
         gboolean ret = FALSE;
+        guint size;
         GPtrArray *clut = NULL;
 
         /* create a lookup table */
-        clut = gcm_session_generate_vcgt (profile,
-                                          gnome_rr_output_get_gamma_size (output));
+        size = gnome_rr_output_get_gamma_size (output);
+        if (size == 0) {
+                g_set_error_literal (error,
+                                     GSD_COLOR_MANAGER_ERROR,
+                                     GSD_COLOR_MANAGER_ERROR_FAILED,
+                                     "gamma size is zero");
+                goto out;
+        }
+        clut = gcm_session_generate_vcgt (profile, size);
         if (clut == NULL) {
                 g_set_error_literal (error,
                                      GSD_COLOR_MANAGER_ERROR,
@@ -868,6 +891,14 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
         g_debug ("falling back to dummy ramp");
         clut = g_ptr_array_new_with_free_func (g_free);
         size = gnome_rr_output_get_gamma_size (output);
+        if (size == 0) {
+                ret = FALSE;
+                g_set_error_literal (error,
+                                     GSD_COLOR_MANAGER_ERROR,
+                                     GSD_COLOR_MANAGER_ERROR_FAILED,
+                                     "gamma size is zero");
+                goto out;
+        }
         for (i = 0; i < size; i++) {
                 value = (i * 0xffff) / (size - 1);
                 data = g_new0 (GnomeRROutputClutItem, 1);



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