changeset 9407:379f59c5b1ff

[gaim-migrate @ 10222] Andrew Wellington says, "Returning a local buffer is not a good idea, it'll work sometimes for some platforms, but the rest of the time it'll give garbage This patch changes oscar_caps_to_string to return a g_malloc()'d block, that is then g_free()'d by the caller." I mostly disagreed with him, but this change doesn't seem like such a bad idea regardless. See http://sourceforge.net/tracker/index.php?func=detail&aid=976213&group_id=235&atid=300235 committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Jun 2004 03:13:04 +0000
parents 0df0a192f382
children 53bf01c6a5ae
files src/protocols/oscar/oscar.c
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/oscar.c	Sat Jun 26 20:33:01 2004 +0000
+++ b/src/protocols/oscar/oscar.c	Sun Jun 27 03:13:04 2004 +0000
@@ -418,12 +418,14 @@
 	return utf8;
 }
 
-static char *oscar_caps_to_string(guint caps)
+gchar *oscar_caps_to_string(guint caps)
 {
-	static char buf[512], *tmp;
-	int count = 0, i = 0;
+	GString *str;
+	gchar *tmp;
 	guint bit = 1;
 
+	str = g_string_new("");
+
 	if (!caps) {
 		return NULL;
 	} else while (bit <= AIM_CAPS_LAST) {
@@ -505,13 +507,12 @@
 				break;
 			}
 			if (tmp)
-				i += g_snprintf(buf + i, sizeof(buf) - i, "%s%s", (count ? ", " : ""),
-						tmp);
-			count++;
+				g_string_append_printf(str, "%s%s", (bit == 1 ? "" : ", "), tmp);
 		}
 		bit <<= 1;
 	}
-	return buf; 
+
+	return g_string_free(str, FALSE);
 }
 
 static char *oscar_icqstatus(int state) {
@@ -596,6 +597,7 @@
 	if ((userinfo != NULL) && (userinfo->capabilities != 0)) {
 		tmp = oscar_caps_to_string(userinfo->capabilities);
 		oscar_string_append(str, newline, _("Capabilities"), tmp);
+		g_free(tmp);
 	}
 
 	if ((b != NULL) && (b->name != NULL) && (g != NULL) && (g->name != NULL)) {