pidgin: 72ecc6ff: A patch from Scott Wolchok to replace sn...

rlaager at pidgin.im rlaager at pidgin.im
Sat May 16 16:00:47 EDT 2009


-----------------------------------------------------------------
Revision: 72ecc6ff2f4db2cc5a95a52ac62c84cd3351b282
Ancestor: 6aee04bda81563906ef0d9d25b7dcd97199de6c6
Author: rlaager at pidgin.im
Date: 2009-05-16T19:58:40
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/72ecc6ff2f4db2cc5a95a52ac62c84cd3351b282

Modified files:
        libpurple/account.c libpurple/blist.c libpurple/dnsquery.c
        libpurple/network.c libpurple/prefs.c
        libpurple/savedstatuses.c libpurple/util.c

ChangeLog: 

A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
increase the size of some buffers to be able to fit -2^63.

I don't think the snprintf() -> g_snprintf() changes do anything with glibc,
but there's no harm in using the glib function to guarantee NUL termination.
Fixes #8974

-------------- next part --------------
============================================================
--- libpurple/account.c	c20d2f91ac5b9ebe011e0e76ea5659f81b327e49
+++ libpurple/account.c	f30d42673ff93f36740312dacb3ee1c876bf2936
@@ -99,7 +99,7 @@ setting_to_xmlnode(gpointer key, gpointe
 	const char *name;
 	PurpleAccountSetting *setting;
 	xmlnode *node, *child;
-	char buf[20];
+	char buf[21];
 
 	name    = (const char *)key;
 	setting = (PurpleAccountSetting *)value;
@@ -110,7 +110,7 @@ setting_to_xmlnode(gpointer key, gpointe
 
 	if (setting->type == PURPLE_PREF_INT) {
 		xmlnode_set_attrib(child, "type", "int");
-		snprintf(buf, sizeof(buf), "%d", setting->value.integer);
+		g_snprintf(buf, sizeof(buf), "%d", setting->value.integer);
 		xmlnode_insert_data(child, buf, -1);
 	}
 	else if (setting->type == PURPLE_PREF_STRING && setting->value.string != NULL) {
@@ -119,7 +119,7 @@ setting_to_xmlnode(gpointer key, gpointe
 	}
 	else if (setting->type == PURPLE_PREF_BOOLEAN) {
 		xmlnode_set_attrib(child, "type", "bool");
-		snprintf(buf, sizeof(buf), "%d", setting->value.boolean);
+		g_snprintf(buf, sizeof(buf), "%d", setting->value.boolean);
 		xmlnode_insert_data(child, buf, -1);
 	}
 }
@@ -281,7 +281,7 @@ proxy_settings_to_xmlnode(PurpleProxyInf
 	PurpleProxyType proxy_type;
 	const char *value;
 	int int_value;
-	char buf[20];
+	char buf[21];
 
 	proxy_type = purple_proxy_info_get_type(proxy_info);
 
@@ -304,7 +304,7 @@ proxy_settings_to_xmlnode(PurpleProxyInf
 
 	if ((int_value = purple_proxy_info_get_port(proxy_info)) != 0)
 	{
-		snprintf(buf, sizeof(buf), "%d", int_value);
+		g_snprintf(buf, sizeof(buf), "%d", int_value);
 		child = xmlnode_new_child(node, "port");
 		xmlnode_insert_data(child, buf, -1);
 	}
@@ -342,7 +342,7 @@ current_error_to_xmlnode(PurpleConnectio
 		return node;
 
 	child = xmlnode_new_child(node, "type");
-	snprintf(type_str, sizeof(type_str), "%u", err->type);
+	g_snprintf(type_str, sizeof(type_str), "%u", err->type);
 	xmlnode_insert_data(child, type_str, -1);
 
 	child = xmlnode_new_child(node, "description");
============================================================
--- libpurple/blist.c	01642a98e686f6a20b9c4777145637a45241024b
+++ libpurple/blist.c	43e0b66e0f974311c31a3fbd2b361dbf123c8948
@@ -125,7 +125,7 @@ value_to_xmlnode(gpointer key, gpointer 
 	const char *name;
 	PurpleValue *value;
 	xmlnode *node, *child;
-	char buf[20];
+	char buf[21];
 
 	name    = (const char *)key;
 	value   = (PurpleValue *)hvalue;
@@ -138,7 +138,7 @@ value_to_xmlnode(gpointer key, gpointer 
 
 	if (purple_value_get_type(value) == PURPLE_TYPE_INT) {
 		xmlnode_set_attrib(child, "type", "int");
-		snprintf(buf, sizeof(buf), "%d", purple_value_get_int(value));
+		g_snprintf(buf, sizeof(buf), "%d", purple_value_get_int(value));
 		xmlnode_insert_data(child, buf, -1);
 	}
 	else if (purple_value_get_type(value) == PURPLE_TYPE_STRING) {
@@ -147,7 +147,7 @@ value_to_xmlnode(gpointer key, gpointer 
 	}
 	else if (purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN) {
 		xmlnode_set_attrib(child, "type", "bool");
-		snprintf(buf, sizeof(buf), "%d", purple_value_get_boolean(value));
+		g_snprintf(buf, sizeof(buf), "%d", purple_value_get_boolean(value));
 		xmlnode_insert_data(child, buf, -1);
 	}
 }
@@ -303,7 +303,7 @@ accountprivacy_to_xmlnode(PurpleAccount 
 	node = xmlnode_new("account");
 	xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account));
 	xmlnode_set_attrib(node, "name", purple_account_get_username(account));
-	snprintf(buf, sizeof(buf), "%d", account->perm_deny);
+	g_snprintf(buf, sizeof(buf), "%d", account->perm_deny);
 	xmlnode_set_attrib(node, "mode", buf);
 
 	for (cur = account->permit; cur; cur = cur->next)
============================================================
--- libpurple/dnsquery.c	64dbfdeff054a4c8eb74f1d6edea1f7871e47c3b
+++ libpurple/dnsquery.c	6e43fe7de94e532ab0653ae0608a54981d3ad865
@@ -325,7 +325,7 @@ cope_with_gdb_brokenness(void)
 		return;
 	already_done = TRUE;
 	ppid = getppid();
-	snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
+	g_snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
 	n = readlink(s, e, sizeof(e));
 	if(n < 0)
 		return;
============================================================
--- libpurple/network.c	b284207842afb12462d73674712c107c0109f903
+++ libpurple/network.c	4b70424840eba4e3105b0edd31ab608783da7f2e
@@ -303,7 +303,7 @@ purple_network_do_listen(unsigned short 
 	/*
 	 * Get a list of addresses on this machine.
 	 */
-	snprintf(serv, sizeof(serv), "%hu", port);
+	g_snprintf(serv, sizeof(serv), "%hu", port);
 	memset(&hints, 0, sizeof(struct addrinfo));
 	hints.ai_flags = AI_PASSIVE;
 	hints.ai_family = AF_UNSPEC;
============================================================
--- libpurple/prefs.c	77ebfb011af30050c11d5f602c7d0e20834d7df5
+++ libpurple/prefs.c	d98de92602ae1b38250bac8c2fd38f76024c91f5
@@ -118,7 +118,7 @@ pref_to_xmlnode(xmlnode *parent, struct 
 {
 	xmlnode *node, *childnode;
 	struct purple_pref *child;
-	char buf[20];
+	char buf[21];
 	GList *cur;
 
 	/* Create a new node */
@@ -128,7 +128,7 @@ pref_to_xmlnode(xmlnode *parent, struct 
 	/* Set the type of this node (if type == PURPLE_PREF_NONE then do nothing) */
 	if (pref->type == PURPLE_PREF_INT) {
 		xmlnode_set_attrib(node, "type", "int");
-		snprintf(buf, sizeof(buf), "%d", pref->value.integer);
+		g_snprintf(buf, sizeof(buf), "%d", pref->value.integer);
 		xmlnode_set_attrib(node, "value", buf);
 	}
 	else if (pref->type == PURPLE_PREF_STRING) {
@@ -161,7 +161,7 @@ pref_to_xmlnode(xmlnode *parent, struct 
 	}
 	else if (pref->type == PURPLE_PREF_BOOLEAN) {
 		xmlnode_set_attrib(node, "type", "bool");
-		snprintf(buf, sizeof(buf), "%d", pref->value.boolean);
+		g_snprintf(buf, sizeof(buf), "%d", pref->value.boolean);
 		xmlnode_set_attrib(node, "value", buf);
 	}
 
============================================================
--- libpurple/savedstatuses.c	ad9a58f04efd207c64052088864f87877fb19482
+++ libpurple/savedstatuses.c	fa593cedc130ed4869721e7daaf5fb7af1d0752c
@@ -285,13 +285,13 @@ status_to_xmlnode(PurpleSavedStatus *sta
 		xmlnode_set_attrib(node, "transient", "true");
 	}
 
-	snprintf(buf, sizeof(buf), "%lu", status->creation_time);
+	g_snprintf(buf, sizeof(buf), "%lu", status->creation_time);
 	xmlnode_set_attrib(node, "created", buf);
 
-	snprintf(buf, sizeof(buf), "%lu", status->lastused);
+	g_snprintf(buf, sizeof(buf), "%lu", status->lastused);
 	xmlnode_set_attrib(node, "lastused", buf);
 
-	snprintf(buf, sizeof(buf), "%u", status->usage_count);
+	g_snprintf(buf, sizeof(buf), "%u", status->usage_count);
 	xmlnode_set_attrib(node, "usage_count", buf);
 
 	child = xmlnode_new_child(node, "state");
============================================================
--- libpurple/util.c	8c4e4787d5558dbb66ce2d53c3d42c468b95e4bf
+++ libpurple/util.c	308f5bd6b8a65d8dc99fe9553dda92f338af5302
@@ -129,7 +129,7 @@ purple_base16_encode(const guchar *data,
 	ascii = g_malloc(len * 2 + 1);
 
 	for (i = 0; i < len; i++)
-		snprintf(&ascii[i * 2], 3, "%02hhx", data[i]);
+		g_snprintf(&ascii[i * 2], 3, "%02hhx", data[i]);
 
 	return ascii;
 }


More information about the Commits mailing list