changeset 32364:323876c34a96

Don't use strlen() when all you're trying to do is check if the string is empty
author Mark Doliner <mark@kingant.net>
date Mon, 22 Aug 2011 02:07:41 +0000
parents 3322201b446f
children e8d4755ef84b
files ChangeLog.API libpurple/protocols/mxit/profile.c libpurple/protocols/mxit/protocol.c libpurple/protocols/null/nullprpl.c libpurple/protocols/oscar/family_feedbag.c libpurple/protocols/sametime/sametime.c libpurple/protocols/zephyr/zephyr.c libpurple/upnp.c libpurple/util.c pidgin/gtkimhtml.c
diffstat 10 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Mon Aug 22 01:53:37 2011 +0000
+++ b/ChangeLog.API	Mon Aug 22 02:07:41 2011 +0000
@@ -9,12 +9,14 @@
 		* purple_request_field_get_tooltip
 
 		Changed:
+		* purple_connection_error now takes a PurpleConnectionError
+		  as the second parameter
+		* purple_notify_user_info_add_pair renamed to
+		  purple_notify_user_info_add_pair_html
 		* purple_util_fetch_url_request_len now takes a PurpleAccount as
 		  the first parameter
 		* PurpleConnectionUiOps.report_disconnect now passes a
 		  PurpleConnectionError as the second parameter
-		* purple_connection_error now takes a PurpleConnectionError
-		  as the second parameter
 
 		Removed:
 		* GtkIMHtml.clipboard_html_string
--- a/libpurple/protocols/mxit/profile.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/mxit/profile.c	Mon Aug 22 02:07:41 2011 +0000
@@ -198,12 +198,12 @@
 	         or if we should be using add_pair_plaintext */
 	purple_notify_user_info_add_pair( info, _( "Country" ), profile->regcountry );
 
-	if ( strlen( profile->aboutme ) > 0 ) {
+	if ( *profile->aboutme ) {
 		/* TODO: Check whether it's correct to call add_pair_html,
 		         or if we should be using add_pair_plaintext */
 		purple_notify_user_info_add_pair( info, _( "About Me" ), profile->aboutme );
 	}
-	if ( strlen( profile->whereami ) > 0 ) {
+	if ( *profile->whereami ) {
 		/* TODO: Check whether it's correct to call add_pair_html,
 		         or if we should be using add_pair_plaintext */
 		purple_notify_user_info_add_pair( info, _( "Where I Live" ), profile->whereami );
--- a/libpurple/protocols/mxit/protocol.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Mon Aug 22 02:07:41 2011 +0000
@@ -1648,7 +1648,7 @@
 
 		if ( rec->fcount >= 5 ) {
 			/* there is a personal invite message attached */
-			if ( ( rec->fields[4]->data ) && ( strlen( rec->fields[4]->data ) > 0 ) )
+			if ( ( rec->fields[4]->data ) && ( *rec->fields[4]->data ) )
 				contact->msg = strdup( rec->fields[4]->data );
 		}
 
@@ -1890,7 +1890,7 @@
 		contact = get_mxit_invite_contact( session, mxitId );
 		if ( contact ) {
 			/* this is an invite, so update its profile info */
-			if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
+			if ( ( statusMsg ) && ( *statusMsg ) ) {
 				/* update the status message */
 				if ( contact->statusMsg )
 					g_free( contact->statusMsg );
@@ -1901,7 +1901,7 @@
 			if ( contact->profile )
 				g_free( contact->profile );
 			contact->profile = profile;
-			if ( ( avatarId ) && ( strlen( avatarId ) > 0 ) ) {
+			if ( ( avatarId ) && ( *avatarId ) ) {
 				/* avatar must be requested for this invite before we can display it */
 				mxit_get_avatar( session, mxitId, avatarId );
 				if ( contact->avatarId )
@@ -1919,7 +1919,7 @@
 			if ( avatarId )
 				mxit_update_buddy_avatar( session, mxitId, avatarId );
 
-			if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
+			if ( ( statusMsg ) && ( *statusMsg ) ) {
 				/* update the status message */
 				PurpleBuddy*		buddy	= NULL;
 
--- a/libpurple/protocols/null/nullprpl.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/null/nullprpl.c	Mon Aug 22 02:07:41 2011 +0000
@@ -234,7 +234,7 @@
     const char *message = purple_status_get_attr_string(status, "message");
 
     char *text;
-    if (message && strlen(message) > 0)
+    if (message && *message)
       text = g_strdup_printf("%s: %s", name, message);
     else
       text = g_strdup(name);
@@ -933,7 +933,7 @@
 
   purple_conv_chat_set_topic(to, username, topic);
 
-  if (topic && strlen(topic) > 0)
+  if (topic && *topic)
     msg = g_strdup_printf(_("%s sets topic to: %s"), username, topic);
   else
     msg = g_strdup_printf(_("%s clears topic"), username);
--- a/libpurple/protocols/oscar/family_feedbag.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/oscar/family_feedbag.c	Mon Aug 22 02:07:41 2011 +0000
@@ -990,7 +990,7 @@
 		return -EINVAL;
 
 	/* Either add or remove the 0x0131 TLV from the TLV chain */
-	if ((alias != NULL) && (strlen(alias) > 0))
+	if (alias && *alias)
 		aim_tlvlist_replace_str(&tmp->data, 0x0131, alias);
 	else
 		aim_tlvlist_remove(&tmp->data, 0x0131);
@@ -1020,7 +1020,7 @@
 		return -EINVAL;
 
 	/* Either add or remove the 0x0131 TLV from the TLV chain */
-	if ((comment != NULL) && (strlen(comment) > 0))
+	if (comment && *comment)
 		aim_tlvlist_replace_str(&tmp->data, 0x013c, comment);
 	else
 		aim_tlvlist_remove(&tmp->data, 0x013c);
--- a/libpurple/protocols/sametime/sametime.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/sametime/sametime.c	Mon Aug 22 02:07:41 2011 +0000
@@ -861,7 +861,7 @@
   enum mwSametimeUserType type = mwSametimeUser_getType(stuser);
 
   g_return_val_if_fail(id != NULL, NULL);
-  g_return_val_if_fail(strlen(id) > 0, NULL);
+  g_return_val_if_fail(*id, NULL);
 
   buddy = purple_find_buddy_in_group(acct, id, group);
   if(! buddy) {
--- a/libpurple/protocols/zephyr/zephyr.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Mon Aug 22 02:07:41 2011 +0000
@@ -2085,7 +2085,7 @@
 	int pos2 = 0;
 	char *newmsg;
 
-	if (message && (strlen(message) > 0)) {
+	if (message && *message) {
 		newmsg = g_new0(char,1+strlen(message)*2);
 		while(pos < strlen(message)) {
 			if (message[pos]=='\\') {
@@ -2117,7 +2117,7 @@
 	int pos2 = 0;
 	char *newmsg;
 
-	if (message && (strlen(message) > 0)) {
+	if (message && *message) {
 		newmsg = g_new0(char,strlen(message)+1);
 		while(pos < strlen(message)) {
 			if (message[pos]=='\\') {
--- a/libpurple/upnp.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/upnp.c	Mon Aug 22 02:07:41 2011 +0000
@@ -744,7 +744,7 @@
 {
 	if (control_info.status == PURPLE_UPNP_STATUS_DISCOVERED
 			&& control_info.publicip
-			&& strlen(control_info.publicip) > 0)
+			&& *control_info.publicip)
 		return control_info.publicip;
 
 	/* Trigger another UPnP discovery if 5 minutes have elapsed since the
@@ -803,7 +803,7 @@
 {
 	if (control_info.status == PURPLE_UPNP_STATUS_DISCOVERED
 			&& control_info.internalip
-			&& strlen(control_info.internalip) > 0)
+			&& *control_info.internalip)
 		return control_info.internalip;
 
 	/* Trigger another UPnP discovery if 5 minutes have elapsed since the
--- a/libpurple/util.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/libpurple/util.c	Mon Aug 22 02:07:41 2011 +0000
@@ -147,7 +147,7 @@
 
 	len = strlen(str);
 
-	g_return_val_if_fail(strlen(str) > 0, 0);
+	g_return_val_if_fail(*str, 0);
 	g_return_val_if_fail(len % 2 == 0,    0);
 
 	data = g_malloc(len / 2);
@@ -2267,7 +2267,7 @@
 					url_buf = g_string_free(gurl_buf, FALSE);
 
 					/* strip off trailing periods */
-					if (strlen(url_buf) > 0) {
+					if (*url_buf) {
 						for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--)
 							*d = '\0';
 					}
--- a/pidgin/gtkimhtml.c	Mon Aug 22 01:53:37 2011 +0000
+++ b/pidgin/gtkimhtml.c	Mon Aug 22 02:07:41 2011 +0000
@@ -5367,9 +5367,9 @@
 			tag = sl->data;
 			/** don't worry about non-printing tags ending */
 			if (tag_ends_here(tag, &iter, &next_iter) &&
-					strlen(tag_to_html_end(tag)) > 0 &&
-					strlen(tag_to_html_start(tag)) > 0) {
-
+					*tag_to_html_end(tag) &&
+					*tag_to_html_start(tag))
+			{
 				PidginTextTagData *tmp;
 				GQueue *r = g_queue_new();