pidgin: bc80dc42: It should be more efficient to just use ...

markdoliner at pidgin.im markdoliner at pidgin.im
Wed Nov 12 04:45:27 EST 2008


-----------------------------------------------------------------
Revision: bc80dc424bc7a7e274901f9124173538e5b43f41
Ancestor: eac2c72efc00cb5ed00e29d52bb7be6fcdc5b3c0
Author: markdoliner at pidgin.im
Date: 2008-11-12T09:40:05
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/bc80dc424bc7a7e274901f9124173538e5b43f41

Modified files:
        libpurple/protocols/msn/httpconn.c
        libpurple/protocols/msn/msg.c

ChangeLog: 

It should be more efficient to just use g_mallc() and then manually
null terminate the buffer, right?

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/httpconn.c	0adb9eb20f8345babc8beb67dfaf1561d9ce37fa
+++ libpurple/protocols/msn/httpconn.c	3e14d93685c2d06aa380d88916433a4618d29e28
@@ -157,8 +157,9 @@ msn_httpconn_parse_data(MsnHttpConn *htt
 		}
 	}
 
-	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",
============================================================
--- libpurple/protocols/msn/msg.c	4b9bf36f796b242543a40820e0dba1c9534cdd6a
+++ libpurple/protocols/msn/msg.c	766882c4ab6fe5389fd2f575f9c9f6f2034cd8e6
@@ -192,8 +192,9 @@ msn_message_parse_slp_body(MsnMessage *m
 
 	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 @@ msn_message_parse_payload(MsnMessage *ms
 	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 @@ msn_message_parse_payload(MsnMessage *ms
 		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 @@ msn_message_parse_payload(MsnMessage *ms
 		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 @@ msn_message_set_bin_data(MsnMessage *msg
 
 	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


More information about the Commits mailing list