[evolution-data-server] Improve camel_file_util_encode_fixed_string()



commit af5ee3533a3ff45c7ac30d58968e0499c72a9e04
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Mar 8 09:30:15 2011 -0500

    Improve camel_file_util_encode_fixed_string()
    
    Allocate the buffer from the heap.  We can't statically declare the
    buffer because it's not a fixed size, and allocating an arbitrarily
    sized buffer on a stack frame is just asking for trouble.

 camel/camel-file-utils.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/camel/camel-file-utils.c b/camel/camel-file-utils.c
index 4d105a8..15aebbd 100644
--- a/camel/camel-file-utils.c
+++ b/camel/camel-file-utils.c
@@ -321,23 +321,26 @@ camel_file_util_decode_string (FILE *in, gchar **str)
 gint
 camel_file_util_encode_fixed_string (FILE *out, const gchar *str, gsize len)
 {
-	gchar buf[len];
-
-	/* Don't allow empty strings to be written */
-	if (len < 1)
-		return -1;
+	gint retval = -1;
 
 	/* Max size is 64K */
 	if (len > 65536)
 		len = 65536;
 
-	memset (buf, 0x00, len);
-	g_strlcpy (buf, str, len);
+	/* Don't allow empty strings to be written. */
+	if (len > 0) {
+		gchar *buf;
 
-	if (fwrite (buf, len, 1, out) == len)
-		return 0;
+		buf = g_malloc0 (len);
+		g_strlcpy (buf, str, len);
 
-	return -1;
+		if (fwrite (buf, len, 1, out) == len)
+			retval = 0;
+
+		g_free (buf);
+	}
+
+	return retval;
 }
 
 /**



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