pidgin: ad72e4ca: Don't use strlen() when all you're tryin...

markdoliner at pidgin.im markdoliner at pidgin.im
Sun Aug 21 22:26:00 EDT 2011


----------------------------------------------------------------------
Revision: ad72e4ca88b0e10549536c1edb35064462d0fc92
Parent:   89cf48c2a62e7c39e8aba3ee2bd90e3ac440151d
Author:   markdoliner at pidgin.im
Date:     08/21/11 22:07:41
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ad72e4ca88b0e10549536c1edb35064462d0fc92

Changelog: 

Don't use strlen() when all you're trying to do is check if the string
is empty

Changes against parent 89cf48c2a62e7c39e8aba3ee2bd90e3ac440151d

  patched  ChangeLog.API
  patched  libpurple/protocols/mxit/profile.c
  patched  libpurple/protocols/mxit/protocol.c
  patched  libpurple/protocols/null/nullprpl.c
  patched  libpurple/protocols/oscar/family_feedbag.c
  patched  libpurple/protocols/sametime/sametime.c
  patched  libpurple/protocols/zephyr/zephyr.c
  patched  libpurple/upnp.c
  patched  libpurple/util.c
  patched  pidgin/gtkimhtml.c

-------------- next part --------------
============================================================
--- libpurple/util.c	3cb82314f944d42ba17a5353dae6be6290c9f196
+++ libpurple/util.c	933911b13d247fcdf4116fd1d9edc9438c112b19
@@ -147,7 +147,7 @@ purple_base16_decode(const char *str, gs
 
 	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 @@ purple_markup_linkify(const char *text)
 					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';
 					}
============================================================
--- pidgin/gtkimhtml.c	66e5bae4676a38c9409259178cf79940fb1c8508
+++ pidgin/gtkimhtml.c	2581c482f2f2aaba8138d76ee5cb535c4207f8ae
@@ -5367,9 +5367,9 @@ char *gtk_imhtml_get_markup_range(GtkIMH
 			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();
 
============================================================
--- libpurple/protocols/zephyr/zephyr.c	371255a3ecc53ff32ed9de04b04a9289e6e75ed2
+++ libpurple/protocols/zephyr/zephyr.c	ce70e656b5705d4b8882d7c223c6454b75d91e84
@@ -2085,7 +2085,7 @@ static char* zephyr_tzc_escape_msg(const
 	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 @@ char* zephyr_tzc_deescape_str(const char
 	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]=='\\') {
============================================================
--- ChangeLog.API	542f487ea59cbb742901120c122e9e5ff91d5192
+++ ChangeLog.API	fdbc8a7565b255b0a014d4f5f880adf3d5be718f
@@ -9,12 +9,14 @@ version 3.0.0 (??/??/????):
 		* 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
============================================================
--- libpurple/protocols/sametime/sametime.c	a13ac515898a542b37e4c4e48c0a6ef8a3278745
+++ libpurple/protocols/sametime/sametime.c	d7c99de708e0cb5734678f08e7afd0de77675ebf
@@ -861,7 +861,7 @@ static PurpleBuddy *buddy_ensure(PurpleC
   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) {
============================================================
--- libpurple/upnp.c	590b03ea3ded09c276877e51c4a8b69100f58005
+++ libpurple/upnp.c	f9a9b04bf11b70f3c05d402c95dd91087242fe1b
@@ -744,7 +744,7 @@ purple_upnp_get_public_ip()
 {
 	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 @@ purple_upnp_get_internal_ip(void)
 {
 	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
============================================================
--- libpurple/protocols/oscar/family_feedbag.c	10437e014d582a11e5e3adc20eac58fba2a5d0b8
+++ libpurple/protocols/oscar/family_feedbag.c	549c9f2e23193ac28d6b4a2718ae2c0129e7821f
@@ -990,7 +990,7 @@ int aim_ssi_aliasbuddy(OscarData *od, co
 		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 @@ int aim_ssi_editcomment(OscarData *od, c
 		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);
============================================================
--- libpurple/protocols/null/nullprpl.c	0cbd5c0bc598c3b8ae77e5d5efe1d7ee6070083d
+++ libpurple/protocols/null/nullprpl.c	b9249aebbf0ed48faae0d654e3adb129173179dc
@@ -234,7 +234,7 @@ static char *nullprpl_status_text(Purple
     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 @@ static void set_chat_topic_fn(PurpleConv
 
   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);
============================================================
--- libpurple/protocols/mxit/profile.c	43fd7ca50b614dd23e82c98c2c0d6298fc2fb282
+++ libpurple/protocols/mxit/profile.c	7092fb1bd098be55eb308444e9d6f879911dd822
@@ -198,12 +198,12 @@ void mxit_show_profile( struct MXitSessi
 	         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 );
============================================================
--- libpurple/protocols/mxit/protocol.c	790299732a39ad8f64bc186ff390518602a4df9c
+++ libpurple/protocols/mxit/protocol.c	10dd7e05b590052e1c4055afc7868956ff000c46
@@ -1648,7 +1648,7 @@ static void mxit_parse_cmd_new_sub( stru
 
 		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 @@ static void mxit_parse_cmd_extprofile( s
 		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 @@ static void mxit_parse_cmd_extprofile( s
 			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 @@ static void mxit_parse_cmd_extprofile( s
 			if ( avatarId )
 				mxit_update_buddy_avatar( session, mxitId, avatarId );
 
-			if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
+			if ( ( statusMsg ) && ( *statusMsg ) ) {
 				/* update the status message */
 				PurpleBuddy*		buddy	= NULL;
 


More information about the Commits mailing list