[gmime/gmime-2-4] Fixed multipart insertion bug



commit 90a83d68152c37db91c596fc40ec758773b5da68
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Nov 5 11:09:17 2009 -0500

    Fixed multipart insertion bug
    
    2009-11-05  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-multipart.c (ptr_array_insert): Fixed to handle an
    	index larger than the current array length as well as fixing the
    	true insert case to shift items when index is les than the current
    	array length (as opposed to when it is equal-to). Thanks to
    	harven gingers rulez pl for finding this bug.

 ChangeLog               |    8 ++++++++
 gmime/gmime-multipart.c |   14 ++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a31591b..a7a5d3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-11-05  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-multipart.c (ptr_array_insert): Fixed to handle an
+	index larger than the current array length as well as fixing the
+	true insert case to shift items when index is les than the current
+	array length (as opposed to when it is equal-to). Thanks to
+	harven gingers rulez pl for finding this bug.
+
 2009-10-10  Jeffrey Stedfast  <fejj novell com>
 
 	* gmime/gmime-utils.c: Fixed the military timezone offsets.
diff --git a/gmime/gmime-multipart.c b/gmime/gmime-multipart.c
index a5d26d8..e4e85d5 100644
--- a/gmime/gmime-multipart.c
+++ b/gmime/gmime-multipart.c
@@ -482,18 +482,20 @@ ptr_array_insert (GPtrArray *array, guint index, gpointer object)
 	unsigned char *dest, *src;
 	guint n;
 	
-	g_ptr_array_set_size (array, array->len + 1);
-	
-	if (index == array->len) {
-		/* need to move items down */
+	if (index < array->len) {
+		/* need to shift some items */
+		g_ptr_array_set_size (array, array->len + 1);
+		
 		dest = ((unsigned char *) array->pdata) + (sizeof (void *) * (index + 1));
 		src = ((unsigned char *) array->pdata) + (sizeof (void *) * index);
 		n = array->len - index - 1;
 		
 		g_memmove (dest, src, (sizeof (void *) * n));
+		array->pdata[index] = object;
+	} else {
+		/* the easy case */
+		g_ptr_array_add (array, object);
 	}
-	
-	array->pdata[index] = object;
 }
 
 static void



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