[gmime] g_mime_iconv_strndup() cleanup



commit 9ab4d7fc16fe0df5d0da55dbe2f8422c66ee21b6
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Sat Jan 30 12:21:02 2010 -0500

    g_mime_iconv_strndup() cleanup
    
    2010-01-30  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-iconv-utils.c (g_mime_iconv_strndup): Cleaned up
    	the code a bit.

 ChangeLog                 |    5 ++++
 gmime/gmime-iconv-utils.c |   59 +++++++++++++++++++++-----------------------
 2 files changed, 33 insertions(+), 31 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a880764..5be059c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-01-30  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-iconv-utils.c (g_mime_iconv_strndup): Cleaned up the
+	code a bit.
+
 2010-01-17  Jeffrey Stedfast  <fejj novell com>
 
 	* gmime/gmime-filter-crlf.c (filter_filter): Fixed bug #606875 by
diff --git a/gmime/gmime-iconv-utils.c b/gmime/gmime-iconv-utils.c
index 2e7ff41..21f668d 100644
--- a/gmime/gmime-iconv-utils.c
+++ b/gmime/gmime-iconv-utils.c
@@ -123,9 +123,30 @@ g_mime_iconv_strndup (iconv_t cd, const char *str, size_t n)
 		outleft = outlen - converted;
 		
 		converted = iconv (cd, (char **) &inbuf, &inleft, &outbuf, &outleft);
-		if (converted == (size_t) -1) {
-			if (errno != E2BIG && errno != EINVAL)
-				goto fail;
+		if (converted != (size_t) -1 || errno == EINVAL) {
+			/*
+			 * EINVAL  An  incomplete  multibyte sequence has been encoun­
+			 *         tered in the input.
+			 *
+			 * We'll just have to ignore it...
+			 */
+			break;
+		}
+		
+		if (errno != E2BIG) {
+			errnosav = errno;
+			
+			w(g_warning ("g_mime_iconv_strndup: %s at byte %lu",
+				     strerror (errno), n - inleft));
+			
+			g_free (out);
+			
+			/* reset the cd */
+			iconv (cd, NULL, NULL, NULL, NULL);
+			
+			errno = errnosav;
+			
+			return NULL;
 		}
 		
 		/*
@@ -135,19 +156,10 @@ g_mime_iconv_strndup (iconv_t cd, const char *str, size_t n)
 		 */
 		
 		converted = outbuf - out;
-		if (errno == E2BIG) {
-			outlen += inleft * 2 + 16;
-			out = g_realloc (out, outlen + 4);
-			outbuf = out + converted;
-		}
-	} while (errno == E2BIG && inleft > 0);
-	
-	/*
-	 * EINVAL  An  incomplete  multibyte sequence has been encoun­
-	 *         tered in the input.
-	 *
-	 * We'll just have to ignore it...
-	 */
+		outlen += inleft * 2 + 16;
+		out = g_realloc (out, outlen + 4);
+		outbuf = out + converted;
+	} while (TRUE);
 	
 	/* flush the iconv conversion */
 	iconv (cd, NULL, NULL, &outbuf, &outleft);
@@ -164,21 +176,6 @@ g_mime_iconv_strndup (iconv_t cd, const char *str, size_t n)
 	iconv (cd, NULL, NULL, NULL, NULL);
 	
 	return out;
-	
- fail:
-	
-	errnosav = errno;
-	
-	w(g_warning ("g_mime_iconv_strndup: %s at byte %lu", strerror (errno), n - inleft));
-	
-	g_free (out);
-	
-	/* reset the cd */
-	iconv (cd, NULL, NULL, NULL, NULL);
-	
-	errno = errnosav;
-	
-	return NULL;
 }
 
 



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