SF.net SVN: geany: [2535] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Apr 27 15:05:40 UTC 2008


Revision: 2535
          http://geany.svn.sourceforge.net/geany/?rev=2535&view=rev
Author:   eht16
Date:     2008-04-27 08:05:40 -0700 (Sun, 27 Apr 2008)

Log Message:
-----------
Fix crash when trying to change the encoding of a file (introduced in r2529).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/document.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-04-27 14:45:36 UTC (rev 2534)
+++ trunk/ChangeLog	2008-04-27 15:05:40 UTC (rev 2535)
@@ -15,6 +15,9 @@
  * autogen.sh:
    Don't check for CVS directory as we don't use CVS anymore and remove
    non-portable -path option of find.
+ * src/document.c:
+   Fix crash when trying to change the encoding of a file
+   (introduced in r2529).
 
 
 2008-04-25  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2008-04-27 14:45:36 UTC (rev 2534)
+++ trunk/src/document.c	2008-04-27 15:05:40 UTC (rev 2535)
@@ -1315,18 +1315,18 @@
 }
 
 
-static gsize save_convert_to_encoding(gint idx, gchar *data, gsize *len)
+static gsize save_convert_to_encoding(gint idx, gchar **data, gsize *len)
 {
 	GError *conv_error = NULL;
 	gchar* conv_file_contents = NULL;
 	gsize bytes_read;
 	gsize conv_len;
 
-	g_return_val_if_fail(data != NULL, FALSE);
+	g_return_val_if_fail(data != NULL || *data == NULL, FALSE);
 	g_return_val_if_fail(len != NULL, FALSE);
 
 	/* try to convert it from UTF-8 to original encoding */
-	conv_file_contents = g_convert(data, *len - 1, doc_list[idx].encoding, "UTF-8",
+	conv_file_contents = g_convert(*data, *len - 1, doc_list[idx].encoding, "UTF-8",
 												&bytes_read, &conv_len, &conv_error);
 
 	if (conv_error != NULL)
@@ -1370,8 +1370,8 @@
 	}
 	else
 	{
-		g_free(data);
-		data = conv_file_contents;
+		g_free(*data);
+		*data = conv_file_contents;
 		*len = conv_len;
 	}
 
@@ -1469,7 +1469,7 @@
 	if (doc_list[idx].encoding != NULL && ! utils_str_equal(doc_list[idx].encoding, "UTF-8") &&
 		! utils_str_equal(doc_list[idx].encoding, encodings[GEANY_ENCODING_NONE].charset))
 	{
-		if  (! save_convert_to_encoding(idx, data, &len))
+		if  (! save_convert_to_encoding(idx, &data, &len))
 		{
 			g_free(data);
 			return FALSE;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list