From 003b067e0d68a1da38415443c44282c7bc34e73e Mon Sep 17 00:00:00 2001 From: qarkai Date: Fri, 24 Mar 2017 12:29:27 +0300 Subject: [PATCH] Remove redundant NULL checks If one of purple_strequal() operands is non-NULL, there is no need to check if other is NULL. --HG-- branch : string-comparison-r2 --- finch/gntrequest.c | 2 +- libpurple/protocols/bonjour/bonjour_ft.c | 40 ++++++++++++---------- libpurple/protocols/bonjour/buddy.c | 2 +- libpurple/protocols/jabber/auth_cyrus.c | 4 +-- libpurple/protocols/jabber/bosh.c | 2 +- libpurple/protocols/jabber/buddy.c | 2 +- libpurple/protocols/jabber/chat.c | 2 +- libpurple/protocols/jabber/disco.c | 6 ++-- libpurple/protocols/jabber/google/google_session.c | 4 +-- libpurple/protocols/jabber/jabber.c | 4 +-- libpurple/protocols/jabber/message.c | 2 +- libpurple/protocols/jabber/parser.c | 2 +- libpurple/protocols/jabber/si.c | 8 ++--- libpurple/protocols/jabber/useravatar.c | 2 +- libpurple/protocols/oscar/clientlogin.c | 6 ++-- libpurple/status.c | 4 +-- pidgin/gtkconv.c | 2 +- pidgin/gtkimhtml.c | 6 ++-- pidgin/gtkprefs.c | 6 ++-- pidgin/gtkrequest.c | 2 +- pidgin/gtkutils.c | 2 +- pidgin/plugins/cap/cap.c | 2 +- 22 files changed, 58 insertions(+), 54 deletions(-) diff --git a/finch/gntrequest.c b/finch/gntrequest.c index 7ec4177883..37521fc0c9 100644 --- a/finch/gntrequest.c +++ b/finch/gntrequest.c @@ -455,7 +455,7 @@ create_string_field(PurpleRequestField *field, GntWidget **username) gnt_entry_set_always_suggest(GNT_ENTRY(entry), TRUE); if (username) *username = entry; - } else if (hint && purple_strequal(hint, "group")) { + } else if (purple_strequal(hint, "group")) { PurpleBlistNode *node; for (node = purple_blist_get_root(); node; node = purple_blist_node_get_sibling_next(node)) { diff --git a/libpurple/protocols/bonjour/bonjour_ft.c b/libpurple/protocols/bonjour/bonjour_ft.c index 43f65a3fd2..cd6bb9b872 100644 --- a/libpurple/protocols/bonjour/bonjour_ft.c +++ b/libpurple/protocols/bonjour/bonjour_ft.c @@ -452,33 +452,37 @@ xep_si_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb) return; if(purple_strequal(type, "set")) { - const char *profile; xmlnode *si; gboolean parsed_receive = FALSE; si = xmlnode_get_child(packet, "si"); purple_debug_info("bonjour", "si offer Message type - SET.\n"); - if (si && (profile = xmlnode_get_attrib(si, "profile")) - && purple_strequal(profile, "http://jabber.org/protocol/si/profile/file-transfer")) { - const char *filename = NULL, *filesize_str = NULL; - goffset filesize = 0; - xmlnode *file; - - const char *sid = xmlnode_get_attrib(si, "id"); - - if ((file = xmlnode_get_child(si, "file"))) { - filename = xmlnode_get_attrib(file, "name"); - if((filesize_str = xmlnode_get_attrib(file, "size"))) - filesize = g_ascii_strtoll(filesize_str, NULL, 10); - } + if (si) { + const char *profile; + + profile = xmlnode_get_attrib(si, "profile"); + + if (purple_strequal(profile, "http://jabber.org/protocol/si/profile/file-transfer")) { + const char *filename = NULL, *filesize_str = NULL; + goffset filesize = 0; + xmlnode *file; + + const char *sid = xmlnode_get_attrib(si, "id"); + + if ((file = xmlnode_get_child(si, "file"))) { + filename = xmlnode_get_attrib(file, "name"); + if((filesize_str = xmlnode_get_attrib(file, "size"))) + filesize = g_ascii_strtoll(filesize_str, NULL, 10); + } - /* TODO: Make sure that it is advertising a bytestreams transfer */ + /* TODO: Make sure that it is advertising a bytestreams transfer */ - if (filename) { - bonjour_xfer_receive(pc, id, sid, name, filesize, filename, XEP_BYTESTREAMS); + if (filename) { + bonjour_xfer_receive(pc, id, sid, name, filesize, filename, XEP_BYTESTREAMS); - parsed_receive = TRUE; + parsed_receive = TRUE; + } } } diff --git a/libpurple/protocols/bonjour/buddy.c b/libpurple/protocols/bonjour/buddy.c index 2c857e157a..1f2f06379e 100644 --- a/libpurple/protocols/bonjour/buddy.c +++ b/libpurple/protocols/bonjour/buddy.c @@ -193,7 +193,7 @@ bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy, PurpleBuddy *buddy) /* Deal with the buddy icon */ old_hash = purple_buddy_icons_get_checksum_for_user(buddy); new_hash = (bonjour_buddy->phsh && *(bonjour_buddy->phsh)) ? bonjour_buddy->phsh : NULL; - if (new_hash && (!old_hash || !purple_strequal(old_hash, new_hash))) { + if (new_hash && !purple_strequal(old_hash, new_hash)) { /* Look up the new icon data */ /* TODO: Make sure the hash assigned to the retrieved buddy icon is the same * as what we looked up. */ diff --git a/libpurple/protocols/jabber/auth_cyrus.c b/libpurple/protocols/jabber/auth_cyrus.c index 83e046325b..7f76160a12 100644 --- a/libpurple/protocols/jabber/auth_cyrus.c +++ b/libpurple/protocols/jabber/auth_cyrus.c @@ -274,7 +274,7 @@ jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply, char **error) js->auth_fail_count++; if (js->auth_fail_count == 1 && - (js->sasl_mechs->str && purple_strequal(js->sasl_mechs->str, "GSSAPI"))) { + purple_strequal(js->sasl_mechs->str, "GSSAPI")) { /* If we tried GSSAPI first, it failed, and it was the only method we had to try, try jabber:iq:auth * for compatibility with iChat 10.5 Server and other jabberd based servers. * @@ -569,7 +569,7 @@ jabber_cyrus_handle_failure(JabberStream *js, xmlnode *packet, return jabber_auth_start_cyrus(js, reply, error); } else if ((js->auth_fail_count == 1) && - (js->current_mech && purple_strequal(js->current_mech, "GSSAPI"))) { + purple_strequal(js->current_mech, "GSSAPI")) { /* If we tried GSSAPI first, it failed, and it was the only method we had to try, try jabber:iq:auth * for compatibility with iChat 10.5 Server and other jabberd based servers. * diff --git a/libpurple/protocols/jabber/bosh.c b/libpurple/protocols/jabber/bosh.c index 9341f5f6e3..af178c64bc 100644 --- a/libpurple/protocols/jabber/bosh.c +++ b/libpurple/protocols/jabber/bosh.c @@ -432,7 +432,7 @@ static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, x type = xmlnode_get_attrib(node, "type"); - if (type != NULL && purple_strequal(type, "terminate")) { + if (purple_strequal(type, "terminate")) { conn->state = BOSH_CONN_OFFLINE; purple_connection_error_reason(conn->js->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c index 4c6266ebf5..4208978137 100644 --- a/libpurple/protocols/jabber/buddy.c +++ b/libpurple/protocols/jabber/buddy.c @@ -2045,7 +2045,7 @@ static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer da * just going to get an error if we send * a cancel, so skip it */ type = xmlnode_get_attrib(result, "type"); - if(type && purple_strequal(type, "cancel")) { + if(purple_strequal(type, "cancel")) { g_free(dir_server); return; } diff --git a/libpurple/protocols/jabber/chat.c b/libpurple/protocols/jabber/chat.c index cde4d4b386..fc532dcc73 100644 --- a/libpurple/protocols/jabber/chat.c +++ b/libpurple/protocols/jabber/chat.c @@ -1226,7 +1226,7 @@ static void jabber_chat_disco_traffic_cb(JabberStream *js, const char *from, for(x = xmlnode_get_child(query, "feature"); x; x = xmlnode_get_next_twin(x)) { const char *var = xmlnode_get_attrib(x, "var"); - if(var && purple_strequal(var, NS_XHTML_IM)) { + if(purple_strequal(var, NS_XHTML_IM)) { chat->xhtml = TRUE; } } diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c index 7610ac7889..4a8c004ebd 100644 --- a/libpurple/protocols/jabber/disco.c +++ b/libpurple/protocols/jabber/disco.c @@ -521,15 +521,15 @@ jabber_disco_server_info_result_cb(JabberStream *js, const char *from, const char *category, *type, *name; category = xmlnode_get_attrib(child, "category"); type = xmlnode_get_attrib(child, "type"); - if(category && type && purple_strequal(category, "pubsub") && purple_strequal(type,"pep")) { + if(purple_strequal(category, "pubsub") && purple_strequal(type, "pep")) { PurpleConnection *gc = js->gc; js->pep = TRUE; gc->flags |= PURPLE_CONNECTION_SUPPORT_MOODS | PURPLE_CONNECTION_SUPPORT_MOOD_MESSAGES; } - if (!category || !purple_strequal(category, "server")) + if (!purple_strequal(category, "server")) continue; - if (!type || !purple_strequal(type, "im")) + if (!purple_strequal(type, "im")) continue; name = xmlnode_get_attrib(child, "name"); diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c index 9ce1648f0a..8130760fea 100644 --- a/libpurple/protocols/jabber/google/google_session.c +++ b/libpurple/protocols/jabber/google/google_session.c @@ -512,7 +512,7 @@ jabber_google_relay_response_session_handle_initiate_cb(GoogleSession *session, id = xmlnode_get_attrib(codec_element, "id"); if (!session_data->video || - (xmlns && purple_strequal(xmlns, NS_GOOGLE_SESSION_PHONE))) { + purple_strequal(xmlns, NS_GOOGLE_SESSION_PHONE)) { clock_rate = xmlnode_get_attrib( codec_element, "clockrate"); video = FALSE; @@ -709,7 +709,7 @@ google_session_handle_accept(JabberStream *js, GoogleSession *session, xmlnode * GList *codecs = NULL, *video_codecs = NULL; JabberIq *result = NULL; const gchar *xmlns = xmlnode_get_namespace(desc_element); - gboolean video = (xmlns && purple_strequal(xmlns, NS_GOOGLE_SESSION_VIDEO)); + gboolean video = purple_strequal(xmlns, NS_GOOGLE_SESSION_VIDEO); GoogleAVSessionData *session_data = (GoogleAVSessionData *) session->session_data; diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c index dc6fe469e2..9d9bdc4f16 100644 --- a/libpurple/protocols/jabber/jabber.c +++ b/libpurple/protocols/jabber/jabber.c @@ -2724,7 +2724,7 @@ char *jabber_parse_error(JabberStream *js, } else if(xmlnode_get_child(error, "undefined-condition")) { text = _("Unknown Error"); } - } else if(xmlns && purple_strequal(xmlns, NS_XMPP_SASL)) { + } else if(purple_strequal(xmlns, NS_XMPP_SASL)) { /* Most common reason can be the default */ SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); if(xmlnode_get_child(packet, "aborted")) { @@ -2751,7 +2751,7 @@ char *jabber_parse_error(JabberStream *js, text = _("Authentication Failure"); } } else if(purple_strequal(packet->name, "stream:error") || - (purple_strequal(packet->name, "error") && xmlns && + (purple_strequal(packet->name, "error") && purple_strequal(xmlns, NS_XMPP_STREAMS))) { /* Most common reason as default: */ SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c index 52ee284f46..967de19f10 100644 --- a/libpurple/protocols/jabber/message.c +++ b/libpurple/protocols/jabber/message.c @@ -182,7 +182,7 @@ static void handle_headline(JabberMessage *jm) for(etc = jm->etc; etc; etc = etc->next) { xmlnode *x = etc->data; const char *xmlns = xmlnode_get_namespace(x); - if(xmlns && purple_strequal(xmlns, NS_OOB_X_DATA)) { + if(purple_strequal(xmlns, NS_OOB_X_DATA)) { xmlnode *url, *desc; char *urltxt, *desctxt; diff --git a/libpurple/protocols/jabber/parser.c b/libpurple/protocols/jabber/parser.c index 14b25d852e..c72c428912 100644 --- a/libpurple/protocols/jabber/parser.c +++ b/libpurple/protocols/jabber/parser.c @@ -191,7 +191,7 @@ jabber_parser_structured_error_handler(void *user_data, xmlErrorPtr error) { JabberStream *js = user_data; - if (error->level == XML_ERR_WARNING && error->message != NULL + if (error->level == XML_ERR_WARNING && purple_strequal(error->message, "xmlns: URI vcard-temp is not absolute\n")) /* * This message happens when parsing vcards, and is normal, so don't diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c index b2bb464aa3..c1635c16fe 100644 --- a/libpurple/protocols/jabber/si.c +++ b/libpurple/protocols/jabber/si.c @@ -1204,14 +1204,14 @@ static void jabber_si_xfer_send_method_cb(JabberStream *js, const char *from, const char *var = xmlnode_get_attrib(field, "var"); JabberSIXfer *jsx = (JabberSIXfer *) xfer->data; - if(var && purple_strequal(var, "stream-method")) { + if(purple_strequal(var, "stream-method")) { if((value = xmlnode_get_child(field, "value"))) { char *val = xmlnode_get_data(value); - if(val && purple_strequal(val, NS_BYTESTREAMS)) { + if(purple_strequal(val, NS_BYTESTREAMS)) { jabber_si_xfer_bytestreams_send_init(xfer); jsx->stream_method |= STREAM_METHOD_BYTESTREAMS; found_method = TRUE; - } else if (val && purple_strequal(val, NS_IBB)) { + } else if (purple_strequal(val, NS_IBB)) { jsx->stream_method |= STREAM_METHOD_IBB; if (!found_method) { /* we haven't tried to init a bytestream session, yet @@ -1749,7 +1749,7 @@ void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type, for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) { const char *var = xmlnode_get_attrib(field, "var"); - if(var && purple_strequal(var, "stream-method")) { + if(purple_strequal(var, "stream-method")) { for(option = xmlnode_get_child(field, "option"); option; option = xmlnode_get_next_twin(option)) { if((value = xmlnode_get_child(option, "value"))) { diff --git a/libpurple/protocols/jabber/useravatar.c b/libpurple/protocols/jabber/useravatar.c index f62763e6d5..152e3d6f85 100644 --- a/libpurple/protocols/jabber/useravatar.c +++ b/libpurple/protocols/jabber/useravatar.c @@ -362,7 +362,7 @@ update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items) break; } /* We'll only pick the png one for now. It's a very nice image format anyways. */ - if(type && id && !goodinfo && purple_strequal(type, "image/png")) + if(id && !goodinfo && purple_strequal(type, "image/png")) goodinfo = info; } } diff --git a/libpurple/protocols/oscar/clientlogin.c b/libpurple/protocols/oscar/clientlogin.c index 714e90234f..713485010e 100644 --- a/libpurple/protocols/oscar/clientlogin.c +++ b/libpurple/protocols/oscar/clientlogin.c @@ -84,17 +84,19 @@ static gchar *generate_error_message(xmlnode *resp, const char *url) { xmlnode *text; xmlnode *status_code_node; - gchar *status_code; gboolean have_error_code = TRUE; gchar *err = NULL; gchar *details = NULL; status_code_node = xmlnode_get_child(resp, "statusCode"); if (status_code_node) { + gchar *status_code; + /* We can get 200 OK here if the server omitted something we think it shouldn't have (see #12783). * No point in showing the "Ok" string to the user. */ - if ((status_code = xmlnode_get_data_unescaped(status_code_node)) && purple_strequal(status_code, "200")) { + status_code = xmlnode_get_data_unescaped(status_code_node); + if (purple_strequal(status_code, "200")) { have_error_code = FALSE; } } diff --git a/libpurple/status.c b/libpurple/status.c index 1161913333..1a08a7012f 100644 --- a/libpurple/status.c +++ b/libpurple/status.c @@ -831,9 +831,7 @@ purple_status_set_active_with_attrs_list(PurpleStatus *status, gboolean active, if (default_value->type == PURPLE_TYPE_STRING) { const char *cur = purple_status_get_attr_string(status, attr->id); const char *def = purple_value_get_string(default_value); - if ((cur == NULL && def == NULL) - || (cur != NULL && def != NULL - && purple_strequal(cur, def))) { + if (purple_strequal(cur, def)) { continue; } diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c index f84d14caa7..fa2db3f3c3 100644 --- a/pidgin/gtkconv.c +++ b/pidgin/gtkconv.c @@ -3540,7 +3540,7 @@ setup_menubar(PidginWindow *win) gtk_item_factory_get_widget(win->menu.item_factory, N_("/Options/Enable Sounds")); method = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/method"); - if (method != NULL && purple_strequal(method, "none")) + if (purple_strequal(method, "none")) { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), FALSE); diff --git a/pidgin/gtkimhtml.c b/pidgin/gtkimhtml.c index ebdea0f620..2680ee2b25 100644 --- a/pidgin/gtkimhtml.c +++ b/pidgin/gtkimhtml.c @@ -3309,13 +3309,13 @@ void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, if (((font->bold && !oldfont->bold) || (oldfont->bold && !font->bold)) && !(options & GTK_IMHTML_NO_FORMATTING)) gtk_imhtml_toggle_bold(imhtml); - if (font->face && (!oldfont->face || !purple_strequal(font->face, oldfont->face)) && !(options & GTK_IMHTML_NO_FONTS)) + if (font->face && !purple_strequal(font->face, oldfont->face) && !(options & GTK_IMHTML_NO_FONTS)) gtk_imhtml_toggle_fontface(imhtml, oldfont->face); - if (font->fore && (!oldfont->fore || !purple_strequal(font->fore, oldfont->fore)) && !(options & GTK_IMHTML_NO_COLOURS)) + if (font->fore && !purple_strequal(font->fore, oldfont->fore) && !(options & GTK_IMHTML_NO_COLOURS)) gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); - if (font->back && (!oldfont->back || !purple_strequal(font->back, oldfont->back)) && !(options & GTK_IMHTML_NO_COLOURS)) + if (font->back && !purple_strequal(font->back, oldfont->back) && !(options & GTK_IMHTML_NO_COLOURS)) gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); } diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c index d5368e70f7..ef0c14bd73 100644 --- a/pidgin/gtkprefs.c +++ b/pidgin/gtkprefs.c @@ -1016,7 +1016,7 @@ prefs_set_blist_theme_cb(GtkComboBox *combo_box, gpointer user_data) gtk_tree_model_get(GTK_TREE_MODEL(prefs_blist_themes), &iter, 2, &name, -1); - if(!name || !purple_strequal(name, "")) + if(!purple_strequal(name, "")) theme = PIDGIN_BLIST_THEME(purple_theme_manager_find_theme(name, "blist")); g_free(name); @@ -1037,7 +1037,7 @@ prefs_set_status_icon_theme_cb(GtkComboBox *combo_box, gpointer user_data) gtk_tree_model_get(GTK_TREE_MODEL(prefs_status_icon_themes), &iter, 2, &name, -1); - if(!name || !purple_strequal(name, "")) + if(!purple_strequal(name, "")) theme = PIDGIN_STATUS_ICON_THEME(purple_theme_manager_find_theme(name, "status-icon")); g_free(name); @@ -1894,7 +1894,7 @@ get_available_browsers(void) browser_setting = NULL; /* If xdg-open is valid, prefer it over gnome-open and skip forward */ if(purple_strequal(possible_browsers[i].command, "xdg-open")) { - if (browser_setting && purple_strequal("gnome-open", browser_setting)) { + if (purple_strequal("gnome-open", browser_setting)) { purple_prefs_set_string(PIDGIN_PREFS_ROOT "/browsers/browser", possible_browsers[i].command); browser_setting = NULL; } diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c index 5058fbb540..f9d93c44e7 100644 --- a/pidgin/gtkrequest.c +++ b/pidgin/gtkrequest.c @@ -809,7 +809,7 @@ setup_entry_field(GtkWidget *entry, PurpleRequestField *field) purple_request_field_is_visible(fld)) { const char *type_hint = purple_request_field_get_type_hint(fld); - if (type_hint != NULL && purple_strequal(type_hint, "account")) + if (purple_strequal(type_hint, "account")) { optmenu = GTK_WIDGET(purple_request_field_get_ui_data(fld)); if (optmenu == NULL) { diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c index 5f93cc1471..8ae28e15b8 100644 --- a/pidgin/gtkutils.c +++ b/pidgin/gtkutils.c @@ -1976,7 +1976,7 @@ add_buddyname_autocomplete_entry(GtkListStore *store, const char *buddy_alias, c when the name and contact alias match. */ if (contact_alias && !purple_strequal(contact_alias, buddyname)) { /* We don't want duplicates when the contact and buddy alias match. */ - if (!buddy_alias || !purple_strequal(contact_alias, buddy_alias)) { + if (!purple_strequal(contact_alias, buddy_alias)) { char *completion_entry = g_strdup_printf("%s \"%s\"", buddyname, contact_alias); char *tmp2 = g_utf8_normalize(contact_alias, -1, G_NORMALIZE_DEFAULT); diff --git a/pidgin/plugins/cap/cap.c b/pidgin/plugins/cap/cap.c index ff6c0d26fe..7e3f7a4ddc 100644 --- a/pidgin/plugins/cap/cap.c +++ b/pidgin/plugins/cap/cap.c @@ -96,7 +96,7 @@ static double generate_prediction_for(PurpleBuddy *buddy) { sta_id = purple_status_get_id(get_status_for(buddy)); - if(sta_id && purple_strequal(sta_id, "offline")) { + if(purple_strequal(sta_id, "offline")) { /* This is kind of stupid, change it. */ if(prediction == 1.0f) prediction = 0.0f; -- 2.11.4.GIT