changeset 24331:7e8175f9b009

It should be more efficient to just use g_mallc() and then manually null terminate the buffer, right?
author Mark Doliner <mark@kingant.net>
date Wed, 12 Nov 2008 09:40:05 +0000
parents 3520b566ce25
children 2b62300d2c19 eb21f65728c0
files libpurple/protocols/msn/httpconn.c libpurple/protocols/msn/msg.c
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/httpconn.c	Wed Nov 12 09:32:10 2008 +0000
+++ b/libpurple/protocols/msn/httpconn.c	Wed Nov 12 09:40:05 2008 +0000
@@ -157,8 +157,9 @@
 		}
 	}
 
-	body = g_malloc0(body_len + 1);
+	body = g_malloc(body_len + 1);
 	memcpy(body, body_start, body_len);
+	body[body_len] = '\0';
 
 #ifdef MSN_DEBUG_HTTP
 	purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n",
--- a/libpurple/protocols/msn/msg.c	Wed Nov 12 09:32:10 2008 +0000
+++ b/libpurple/protocols/msn/msg.c	Wed Nov 12 09:40:05 2008 +0000
@@ -192,8 +192,9 @@
 
 	if (body_len > 0) {
 		msg->body_len = len - (tmp - body);
-		msg->body = g_malloc0(msg->body_len + 1);
+		msg->body = g_malloc(msg->body_len + 1);
 		memcpy(msg->body, tmp, msg->body_len);
+		msg->body[msg->body_len] = '\0';
 		tmp += body_len;
 	}
 }
@@ -209,8 +210,9 @@
 	char **elems, **cur, **tokens;
 
 	g_return_if_fail(payload != NULL);
-	tmp_base = tmp = g_malloc0(payload_len + 1);
+	tmp_base = tmp = g_malloc(payload_len + 1);
 	memcpy(tmp_base, payload, payload_len);
+	tmp_base[payload_len] = '\0';
 
 	/* Parse the attributes. */
 	end = strstr(tmp, body_dem);
@@ -308,8 +310,9 @@
 		if (body_len > 0) {
 			msg->body_len = body_len;
 			g_free(msg->body);
-			msg->body = g_malloc0(msg->body_len + 1);
+			msg->body = g_malloc(msg->body_len + 1);
 			memcpy(msg->body, tmp, msg->body_len);
+			msg->body[msg->body_len] = '\0';
 			tmp += body_len;
 		}
 
@@ -325,8 +328,9 @@
 		if (payload_len - (tmp - tmp_base) > 0) {
 			msg->body_len = payload_len - (tmp - tmp_base);
 			g_free(msg->body);
-			msg->body = g_malloc0(msg->body_len + 1);
+			msg->body = g_malloc(msg->body_len + 1);
 			memcpy(msg->body, tmp, msg->body_len);
+			msg->body[msg->body_len] = '\0';
 		}
 	}
 
@@ -523,8 +527,9 @@
 
 	if (data != NULL && len > 0)
 	{
-		msg->body = g_malloc0(len + 1);
+		msg->body = g_malloc(len + 1);
 		memcpy(msg->body, data, len);
+		msg->body[len] = '\0';
 		msg->body_len = len;
 	}
 	else