[gmime/gmime-2-4] Another iconv flush fix



commit 69482525bfd7b4d02771ded7d37b176c61b9abfa
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Dec 15 22:34:02 2011 -0500

    Another iconv flush fix
    
    2011-12-15  Jeffrey Stedfast  <fejj gnome org>
    
    	* gmime/gmime-iconv-utils.c (g_mime_iconv_strndup): Same.

 ChangeLog                 |    2 ++
 gmime/gmime-iconv-utils.c |   11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c0b7558..1302fec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2011-12-15  Jeffrey Stedfast  <fejj gnome org>
 
+	* gmime/gmime-iconv-utils.c (g_mime_iconv_strndup): Same.
+
 	* gmime/gmime-filter-charset.c (flter_complete): Same as
 	charset_convert().
 
diff --git a/gmime/gmime-iconv-utils.c b/gmime/gmime-iconv-utils.c
index 4e33dfa..8e02659 100644
--- a/gmime/gmime-iconv-utils.c
+++ b/gmime/gmime-iconv-utils.c
@@ -150,7 +150,16 @@ g_mime_iconv_strndup (iconv_t cd, const char *str, size_t n)
 	 */
 	
 	/* flush the iconv conversion */
-	iconv (cd, NULL, NULL, &outbuf, &outleft);
+	while (iconv (cd, NULL, NULL, &outbuf, &outleft) == (size_t) -1) {
+		if (errno != E2BIG)
+			break;
+		
+		outlen += 16;
+		converted = outbuf - out;
+		out = g_realloc (out, outlen + 4);
+		outleft = outlen - converted;
+		outbuf = out + converted;
+	}
 	
 	/* Note: not all charsets can be nul-terminated with a single
            nul byte. UCS2, for example, needs 2 nul bytes and UCS4



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