changeset 17673:d125c3562280

In msim_tooltip_text, do not try to display items with no value. In Linux, "%s" on a null pointer is formatted as "(null)", but on Windows this leads to a crash. Closes #1999.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 01 Jul 2007 23:33:27 +0000
parents d43314277ccc
children e24d44e3b6d2
files libpurple/protocols/myspace/myspace.c
diffstat 1 files changed, 35 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Sun Jul 01 23:12:38 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sun Jul 01 23:33:27 2007 +0000
@@ -2503,6 +2503,9 @@
 msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, 
 		gboolean full)
 {
+	const gchar *str, *str2;
+	gint n;
+
     g_return_if_fail(buddy != NULL);
     g_return_if_fail(user_info != NULL);
 
@@ -2516,32 +2519,43 @@
 
         /* TODO: if (full), do something different */
 		
-		/* Useful to identify the account the tooltip refers to. Other prpls show this. */
-		purple_notify_user_info_add_pair(user_info, _("User Name"),
-				(purple_blist_node_get_string(&buddy->node, "UserName"))); 
+		/* Useful to identify the account the tooltip refers to. 
+		 *  Other prpls show this. */
+		str = purple_blist_node_get_string(&buddy->node, "UserName"); 
+		if (str)
+			purple_notify_user_info_add_pair(user_info, _("User Name"), str);
 
 		/* a/s/l...the vitals */	
-		purple_notify_user_info_add_pair(user_info, _("Age"),
-				g_strdup_printf("%d", purple_blist_node_get_int(&buddy->node, "Age")));
-
-		purple_notify_user_info_add_pair(user_info, _("Gender"),
-				(purple_blist_node_get_string(&buddy->node, "Gender")));
-
-		purple_notify_user_info_add_pair(user_info, _("Location"),
-				(purple_blist_node_get_string(&buddy->node, "Location")));
+		n = purple_blist_node_get_int(&buddy->node, "Age");
+		if (n)
+			purple_notify_user_info_add_pair(user_info, _("Age"),
+					g_strdup_printf("%d", n));
+
+		str = purple_blist_node_get_string(&buddy->node, "Gender");
+		if (str)
+			purple_notify_user_info_add_pair(user_info, _("Gender"), str);
+
+		str = purple_blist_node_get_string(&buddy->node, "Location");
+		if (str)
+			purple_notify_user_info_add_pair(user_info, _("Location"), str);
 
 		/* Other information */
- 		if (purple_blist_node_get_string(&buddy->node, "Headline"))
-			purple_notify_user_info_add_pair(user_info, _("Headline"),
-					(purple_blist_node_get_string(&buddy->node, "Headline"))); 
-
-	    purple_notify_user_info_add_pair(user_info, _("Song"), 
+ 		str = purple_blist_node_get_string(&buddy->node, "Headline");
+		if (str)
+			purple_notify_user_info_add_pair(user_info, _("Headline"), str);
+
+		str = purple_blist_node_get_string(&buddy->node, "BandName");
+		str2 = purple_blist_node_get_string(&buddy->node, "SongName");
+		if (str || str2)
+			purple_notify_user_info_add_pair(user_info, _("Song"), 
                 g_strdup_printf("%s - %s",
-					purple_blist_node_get_string(&buddy->node, "BandName"),
-					purple_blist_node_get_string(&buddy->node, "SongName")));
-
-		purple_notify_user_info_add_pair(user_info, _("Total Friends"),
-				g_strdup_printf("%d", purple_blist_node_get_int(&buddy->node, "TotalFriends")));
+					str ? str : _("Unknown Artist"),
+					str2 ? str2 : _("Unknown Song")));
+
+		n = purple_blist_node_get_int(&buddy->node, "TotalFriends");
+		if (n)
+			purple_notify_user_info_add_pair(user_info, _("Total Friends"),
+				g_strdup_printf("%d", n));
 
     }
 }