[gmime/gmime-2-4] Grow the iconv output buffer on flush when E2BIG



commit 578e50667264f56f7f8f2c171f166766361919c4
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Dec 15 22:06:37 2011 -0500

    Grow the iconv output buffer on flush when E2BIG
    
    2011-12-15  Jeffrey Stedfast  <fejj gnome org>
    
    	* gmime/gmime-utils.c (charset_convert): Make sure the output
    	buffer is large enough when flushing the conversion descriptor.

 ChangeLog           |    5 +++++
 gmime/gmime-utils.c |   12 +++++++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2cf2aeb..1ee1bb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-12-15  Jeffrey Stedfast  <fejj gnome org>
 
+	* gmime/gmime-utils.c (charset_convert): Make sure the output
+	buffer is large enough when flushing the conversion descriptor.
+
+2011-12-15  Jeffrey Stedfast  <fejj gnome org>
+
 	* gmime/gmime.c (g_mime_init): Don't initialize the crypto types
 	unless crypto was enabled in the build.
 
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 18c01fb..d97316e 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -1557,7 +1557,17 @@ charset_convert (iconv_t cd, const char *inbuf, size_t inleft, char **outp, size
 		}
 	} while (inleft > 0);
 	
-	iconv (cd, NULL, NULL, &outbuf, &outleft);
+	while (iconv (cd, NULL, NULL, &outbuf, &outleft) == (size_t) -1) {
+		if (errno != E2BIG)
+			break;
+		
+		outlen += 16;
+		rc = (size_t) (outbuf - out);
+		out = g_realloc (out, outlen + 1);
+		outleft = outlen - rc;
+		outbuf = out + rc;
+	}
+	
 	*outbuf++ = '\0';
 	
 	*outlenp = outlen;



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