changeset 28726:f6f35d5960e9

Use g_strndup() for great justice.
author Paul Aurich <paul@darkrain42.org>
date Tue, 01 Dec 2009 02:54:22 +0000
parents 51d82a66e247
children 6ebacc1710b2
files libpurple/protocols/jabber/parser.c libpurple/xmlnode.c
diffstat 2 files changed, 3 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/parser.c	Mon Nov 30 15:46:58 2009 +0000
+++ b/libpurple/protocols/jabber/parser.c	Tue Dec 01 02:54:22 2009 +0000
@@ -47,9 +47,7 @@
 		js->protocol_version = JABBER_PROTO_0_9;
 		for(i=0; i < nb_attributes * 5; i += 5) {
 			int attrib_len = attributes[i+4] - attributes[i+3];
-			char *attrib = g_malloc(attrib_len + 1);
-			memcpy(attrib, attributes[i+3], attrib_len);
-			attrib[attrib_len] = '\0';
+			char *attrib = g_strndup((gchar *)attributes[i+3], attrib_len);
 
 			if(!xmlStrcmp(attributes[i], (xmlChar*) "version")
 					&& !strcmp(attrib, "1.0")) {
@@ -88,10 +86,7 @@
 			const char *attrib_ns = (const char *)attributes[i+2];
 			char *txt;
 			int attrib_len = attributes[i+4] - attributes[i+3];
-			char *attrib = g_malloc(attrib_len + 1);
-
-			memcpy(attrib, attributes[i+3], attrib_len);
-			attrib[attrib_len] = '\0';
+			char *attrib = g_strndup((gchar *)attributes[i+3], attrib_len);
 
 			txt = attrib;
 			attrib = purple_unescape_html(txt);
--- a/libpurple/xmlnode.c	Mon Nov 30 15:46:58 2009 +0000
+++ b/libpurple/xmlnode.c	Tue Dec 01 02:54:22 2009 +0000
@@ -588,9 +588,7 @@
 			const char *prefix = (const char *)attributes[i+1];
 			char *txt;
 			int attrib_len = attributes[i+4] - attributes[i+3];
-			char *attrib = g_malloc(attrib_len + 1);
-			memcpy(attrib, attributes[i+3], attrib_len);
-			attrib[attrib_len] = '\0';
+			char *attrib = g_strndup(attributes[i+3], attrib_len);
 			txt = attrib;
 			attrib = purple_unescape_html(txt);
 			g_free(txt);