[gnome-desktop] Don't use fixed-length arrays for EDID



commit cd51db012316b571f03e7557b1159a7cbbcfcdeb
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 9 11:01:14 2010 +0000

    Don't use fixed-length arrays for EDID
    
    Use variable-length variables instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=612276

 libgnome-desktop/edid-parse.c      |   48 ++++++++++++++++++++++++++++++------
 libgnome-desktop/edid.h            |    9 +++---
 libgnome-desktop/gnome-rr-config.c |    2 +-
 3 files changed, 46 insertions(+), 13 deletions(-)
---
diff --git a/libgnome-desktop/edid-parse.c b/libgnome-desktop/edid-parse.c
index 225778a..ef00682 100644
--- a/libgnome-desktop/edid-parse.c
+++ b/libgnome-desktop/edid-parse.c
@@ -349,27 +349,44 @@ decode_standard_timings (const uchar *edid, MonitorInfo *info)
     return TRUE;
 }
 
-static void
-decode_lf_string (const uchar *s, int n_chars, char *result)
+static char *
+decode_lf_string (const uchar *s, int n_chars, char *prev)
 {
     int i;
+    char *ret, *tmp;
+
+    tmp = g_malloc0 (n_chars);
+
     for (i = 0; i < n_chars; ++i)
     {
 	if (s[i] == 0x0a)
 	{
-	    *result++ = '\0';
+	    tmp[i] = '\0';
 	    break;
 	}
 	else if (s[i] == 0x00)
 	{
 	    /* Convert embedded 0's to spaces */
-	    *result++ = ' ';
+	    tmp[i] = ' ';
 	}
 	else
 	{
-	    *result++ = s[i];
+	    tmp[i] = s[i];
 	}
     }
+
+    if (prev)
+    {
+       ret = g_strjoin(NULL, prev, tmp, NULL);
+       g_free(prev);
+       g_free(tmp);
+    }
+    else
+    {
+       ret = tmp;
+    }
+
+    return ret;
 }
 
 static void
@@ -379,13 +396,16 @@ decode_display_descriptor (const uchar *desc,
     switch (desc[0x03])
     {
     case 0xFC:
-	decode_lf_string (desc + 5, 13, info->dsc_product_name);
+	info->dsc_product_name = decode_lf_string (desc + 5, 13,
+                                                   info->dsc_product_name);
 	break;
     case 0xFF:
-	decode_lf_string (desc + 5, 13, info->dsc_serial_number);
+	info->dsc_serial_number = decode_lf_string (desc + 5, 13,
+                                                    info->dsc_serial_number);
 	break;
     case 0xFE:
-	decode_lf_string (desc + 5, 13, info->dsc_string);
+	info->dsc_string = decode_lf_string (desc + 5, 13,
+                                             info->dsc_string);
 	break;
     case 0xFD:
 	/* Range Limits */
@@ -514,6 +534,18 @@ decode_check_sum (const uchar *edid,
     info->checksum = check;
 }
 
+void
+free_edid (MonitorInfo *info)
+{
+    if (info)
+    {
+	g_free (info->dsc_product_name);
+	g_free (info->dsc_serial_number);
+	g_free (info->dsc_string);
+    }
+    g_free (info);
+}
+
 MonitorInfo *
 decode_edid (const uchar *edid)
 {
diff --git a/libgnome-desktop/edid.h b/libgnome-desktop/edid.h
index 55f0bfa..dbfd83c 100644
--- a/libgnome-desktop/edid.h
+++ b/libgnome-desktop/edid.h
@@ -183,12 +183,13 @@ struct MonitorInfo
 						 */
 
     /* Optional product description */
-    char		dsc_serial_number[14];
-    char		dsc_product_name[14];
-    char		dsc_string[14];		/* Unspecified ASCII data */
+    char	       *dsc_serial_number;
+    char	       *dsc_product_name;
+    char	       *dsc_string;		/* Unspecified ASCII data */
 };
 
 MonitorInfo *decode_edid (const uchar *data);
-char *make_display_name (const MonitorInfo *info);
+void         free_edid (MonitorInfo *);
+char *       make_display_name (const MonitorInfo *info);
 
 #endif
diff --git a/libgnome-desktop/gnome-rr-config.c b/libgnome-desktop/gnome-rr-config.c
index 15ff0a3..f2f8987 100644
--- a/libgnome-desktop/gnome-rr-config.c
+++ b/libgnome-desktop/gnome-rr-config.c
@@ -502,7 +502,7 @@ gnome_rr_config_new_current (GnomeRRScreen *screen)
 	    else
 		output->display_name = make_display_name (info);
 		
-	    g_free (info);
+	    free_edid (info);
 		
 	    crtc = gnome_rr_output_get_crtc (rr_output);
 	    mode = crtc? gnome_rr_crtc_get_current_mode (crtc) : NULL;



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