From c955c04d8fe23db7330066e8dffbb3f1bf0d3174 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 13 Mar 2016 22:11:01 +0000 Subject: [PATCH] Explicitly compare result of str(n)cmp/memcmp to signify that it's not boolean --- cli/cli.c | 4 +- daemon/remote.c | 16 +- gtk/actions.c | 2 +- gtk/details.c | 12 +- gtk/file-list.c | 2 +- gtk/filter.c | 4 +- gtk/main.c | 66 +++---- gtk/tr-core.c | 18 +- gtk/tr-window.c | 8 +- gtk/util.c | 2 +- libtransmission/announcer-http.c | 2 +- libtransmission/announcer-udp.c | 2 +- libtransmission/announcer.c | 28 +-- libtransmission/clients.c | 262 ++++++++++++------------- libtransmission/handshake.c | 14 +- libtransmission/inout.c | 2 +- libtransmission/libtransmission-test.c | 2 +- libtransmission/magnet.c | 10 +- libtransmission/metainfo.c | 4 +- libtransmission/platform-quota.c | 12 +- libtransmission/platform.c | 4 +- libtransmission/quark.c | 2 +- libtransmission/rename-test.c | 4 +- libtransmission/resume.c | 8 +- libtransmission/rpc-server.c | 18 +- libtransmission/rpcimpl.c | 22 +-- libtransmission/session-test.c | 2 +- libtransmission/session.c | 6 +- libtransmission/torrent-magnet.c | 2 +- libtransmission/torrent.c | 22 +-- libtransmission/tr-getopt.c | 6 +- libtransmission/utils.c | 4 +- libtransmission/variant-test.c | 4 +- libtransmission/variant.c | 4 +- libtransmission/verify.c | 2 +- macosx/main.m | 2 +- qt/OptionsDialog.cc | 6 +- qt/Session.cc | 6 +- utils/edit.c | 6 +- utils/show.c | 2 +- 40 files changed, 302 insertions(+), 302 deletions(-) diff --git a/cli/cli.c b/cli/cli.c index 475617358..3028ae0b5 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -290,11 +290,11 @@ tr_main (int argc, { tr_ctorSetMetainfo (ctor, fileContents, fileLength); } - else if (!memcmp (torrentPath, "magnet:?", 8)) + else if (memcmp (torrentPath, "magnet:?", 8) == 0) { tr_ctorSetMetainfoFromMagnetLink (ctor, torrentPath); } - else if (!memcmp (torrentPath, "http", 4)) + else if (memcmp (torrentPath, "http", 4) == 0) { tr_webRun (h, torrentPath, onTorrentFileDownloaded, ctor); waitingOnWeb = true; diff --git a/daemon/remote.c b/daemon/remote.c index 5e21afdcb..0ec7b4989 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -519,11 +519,11 @@ addIdArg (tr_variant * args, const char * id, const char * fallback) } } - if (!tr_strcmp0 (id, "active")) + if (tr_strcmp0 (id, "active") == 0) { tr_variantDictAddStr (args, TR_KEY_ids, "recently-active"); } - else if (strcmp (id, "all")) + else if (strcmp (id, "all") != 0) { const char * pch; bool isList = strchr (id,',') || strchr (id,'-'); @@ -611,7 +611,7 @@ addFiles (tr_variant * args, arg = "-1"; /* no file will have this index, so should be a no-op */ } - if (strcmp (arg, "all")) + if (strcmp (arg, "all") != 0) { int i; int valueCount; @@ -718,7 +718,7 @@ parseResponseHeader (void *ptr, size_t size, size_t nmemb, void * stream UNUSED) const char * key = TR_RPC_SESSION_ID_HEADER ": "; const size_t key_len = strlen (key); - if ((line_len >= key_len) && !memcmp (line, key, key_len)) + if (line_len >= key_len && memcmp (line, key, key_len) == 0) { const char * begin = line + key_len; const char * end = begin; @@ -1641,7 +1641,7 @@ processResponse (const char * rpcurl, const void * response, size_t len) if (tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL)) { - if (strcmp (str, "success")) + if (strcmp (str, "success") != 0) { printf ("Error: %s\n", str); status |= EXIT_FAILURE; @@ -1693,7 +1693,7 @@ processResponse (const char * rpcurl, const void * response, size_t len) status |= EXIT_FAILURE; else { printf ("%s responded: \"%s\"\n", rpcurl, str); - if (strcmp (str, "success")) + if (strcmp (str, "success") != 0) status |= EXIT_FAILURE; } } @@ -2327,11 +2327,11 @@ getHostAndPortAndRpcUrl (int * argc, char ** argv, int i; const char * s = argv[1]; const char * delim = strchr (s, ':'); - if (!strncmp (s, "http://", 7)) /* user passed in http rpc url */ + if (strncmp (s, "http://", 7) == 0) /* user passed in http rpc url */ { *rpcurl = tr_strdup_printf ("%s/rpc/", s + 7); } - else if (!strncmp (s, "https://", 8)) /* user passed in https rpc url */ + else if (strncmp (s, "https://", 8) == 0) /* user passed in https rpc url */ { UseSSL = true; *rpcurl = tr_strdup_printf ("%s/rpc/", s + 8); diff --git a/gtk/actions.c b/gtk/actions.c index 3518998da..3d1c59c08 100644 --- a/gtk/actions.c +++ b/gtk/actions.c @@ -210,7 +210,7 @@ gtr_actions_init (GtkUIManager * ui_manager, gpointer callback_user_data) match = gtr_pref_string_get (TR_KEY_sort_mode); for (i = 0, n = G_N_ELEMENTS (sort_radio_entries), active = -1; active == -1 && i < n; ++i) - if (!g_strcmp0 (sort_radio_entries[i].name, match)) + if (g_strcmp0 (sort_radio_entries[i].name, match) == 0) active = i; gtk_action_group_add_radio_actions (action_group, diff --git a/gtk/details.c b/gtk/details.c index 5ffae31f1..7c3a89cfc 100644 --- a/gtk/details.c +++ b/gtk/details.c @@ -609,7 +609,7 @@ gtr_text_buffer_set_text (GtkTextBuffer * b, const char * str) gtk_text_buffer_get_bounds (b, &start, &end); old_str = gtk_text_buffer_get_text (b, &start, &end, FALSE); - if ((old_str == NULL) || g_strcmp0 (old_str, str)) + if (old_str == NULL || g_strcmp0 (old_str, str) != 0) gtk_text_buffer_set_text (b, str, -1); g_free (old_str); @@ -686,7 +686,7 @@ refreshInfo (struct DetailsImpl * di, tr_torrent ** torrents, int n) for (i=1; icreator ? infos[i]->creator : ""); + mixed_creator |= g_strcmp0 (creator, infos[i]->creator ? infos[i]->creator : "") != 0; mixed_date |= (date != infos[i]->dateCreated); } @@ -727,7 +727,7 @@ refreshInfo (struct DetailsImpl * di, tr_torrent ** torrents, int n) const char * baseline = infos[0]->comment ? infos[0]->comment : ""; for (i=1; icomment ? infos[i]->comment : "")) + if (g_strcmp0 (baseline, infos[i]->comment ? infos[i]->comment : "") != 0) break; if (i==n) @@ -747,7 +747,7 @@ refreshInfo (struct DetailsImpl * di, tr_torrent ** torrents, int n) const char * baseline = tr_torrentGetDownloadDir (torrents[0]); for (i=1; ierrorString; for (i=1; ierrorString)) + if (g_strcmp0 (baseline, stats[i]->errorString) != 0) break; if (i==n) @@ -1286,7 +1286,7 @@ initPeerRow (GtkListStore * store, char collated_name[128]; const char * client = peer->client; - if (!client || !g_strcmp0 (client, "Unknown Client")) + if (client == NULL || g_strcmp0 (client, "Unknown Client") == 0) client = ""; if (sscanf (peer->addr, "%d.%d.%d.%d", q, q+1, q+2, q+3) != 4) diff --git a/gtk/file-list.c b/gtk/file-list.c index 0f4f8f164..da8fb82eb 100644 --- a/gtk/file-list.c +++ b/gtk/file-list.c @@ -484,7 +484,7 @@ find_child (GNode* parent, const char * name) while (child) { const struct row_struct * child_data = child->data; - if ((*child_data->name == *name) && !g_strcmp0 (child_data->name, name)) + if (*child_data->name == *name && g_strcmp0 (child_data->name, name) == 0) break; child = child->next; } diff --git a/gtk/filter.c b/gtk/filter.c index 5a967752c..abeb2804f 100644 --- a/gtk/filter.c +++ b/gtk/filter.c @@ -160,7 +160,7 @@ tracker_filter_model_update (gpointer gstore) } for (k=0; ktrackerCount; ++i) { gtr_get_host_from_url (tmp, sizeof (tmp), inf->trackers[i].announce); - if (!g_strcmp0 (tmp, host)) + if (g_strcmp0 (tmp, host) == 0) break; } diff --git a/gtk/main.c b/gtk/main.c index c80814e3a..00604bf28 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -167,7 +167,7 @@ show_details_dialog_for_selected_torrents (struct cbdata * data) char * key = get_details_dialog_key (ids); for (l=data->details; dialog==NULL && l!=NULL; l=l->next) - if (!g_strcmp0 (key, g_object_get_data (l->data, "key"))) + if (g_strcmp0 (key, g_object_get_data (l->data, "key")) == 0) dialog = l->data; if (dialog == NULL) @@ -1529,35 +1529,35 @@ gtr_actions_handler (const char * action_name, gpointer user_data) gboolean changed = FALSE; struct cbdata * data = user_data; - if (!g_strcmp0 (action_name, "open-torrent-from-url")) + if (g_strcmp0 (action_name, "open-torrent-from-url") == 0) { GtkWidget * w = gtr_torrent_open_from_url_dialog_new (data->wind, data->core); gtk_widget_show (w); } - else if (!g_strcmp0 (action_name, "open-torrent-menu") - || !g_strcmp0 (action_name, "open-torrent-toolbar")) + else if (g_strcmp0 (action_name, "open-torrent-menu") == 0 + || g_strcmp0 (action_name, "open-torrent-toolbar") == 0) { GtkWidget * w = gtr_torrent_open_from_file_dialog_new (data->wind, data->core); gtk_widget_show (w); } - else if (!g_strcmp0 (action_name, "show-stats")) + else if (g_strcmp0 (action_name, "show-stats") == 0) { GtkWidget * dialog = gtr_stats_dialog_new (data->wind, data->core); gtk_widget_show (dialog); } - else if (!g_strcmp0 (action_name, "donate")) + else if (g_strcmp0 (action_name, "donate") == 0) { gtr_open_uri ("http://www.transmissionbt.com/donate.php"); } - else if (!g_strcmp0 (action_name, "pause-all-torrents")) + else if (g_strcmp0 (action_name, "pause-all-torrents") == 0) { pause_all_torrents (data); } - else if (!g_strcmp0 (action_name, "start-all-torrents")) + else if (g_strcmp0 (action_name, "start-all-torrents") == 0) { start_all_torrents (data); } - else if (!g_strcmp0 (action_name, "copy-magnet-link-to-clipboard")) + else if (g_strcmp0 (action_name, "copy-magnet-link-to-clipboard") == 0) { tr_torrent * tor = get_first_selected_torrent (data); if (tor != NULL) @@ -1565,7 +1565,7 @@ gtr_actions_handler (const char * action_name, gpointer user_data) copy_magnet_link_to_clipboard (GTK_WIDGET (data->wind), tor); } } - else if (!g_strcmp0 (action_name, "relocate-torrent")) + else if (g_strcmp0 (action_name, "relocate-torrent") == 0) { GSList * ids = get_selected_torrent_ids (data); if (ids != NULL) @@ -1575,52 +1575,52 @@ gtr_actions_handler (const char * action_name, gpointer user_data) gtk_widget_show (w); } } - else if (!g_strcmp0 (action_name, "torrent-start") - || !g_strcmp0 (action_name, "torrent-start-now") - || !g_strcmp0 (action_name, "torrent-stop") - || !g_strcmp0 (action_name, "torrent-reannounce") - || !g_strcmp0 (action_name, "torrent-verify") - || !g_strcmp0 (action_name, "queue-move-top") - || !g_strcmp0 (action_name, "queue-move-up") - || !g_strcmp0 (action_name, "queue-move-down") - || !g_strcmp0 (action_name, "queue-move-bottom")) + else if (g_strcmp0 (action_name, "torrent-start") == 0 + || g_strcmp0 (action_name, "torrent-start-now") == 0 + || g_strcmp0 (action_name, "torrent-stop") == 0 + || g_strcmp0 (action_name, "torrent-reannounce") == 0 + || g_strcmp0 (action_name, "torrent-verify") == 0 + || g_strcmp0 (action_name, "queue-move-top") == 0 + || g_strcmp0 (action_name, "queue-move-up") == 0 + || g_strcmp0 (action_name, "queue-move-down") == 0 + || g_strcmp0 (action_name, "queue-move-bottom") == 0) { changed |= call_rpc_for_selected_torrents (data, action_name); } - else if (!g_strcmp0 (action_name, "open-torrent-folder")) + else if (g_strcmp0 (action_name, "open-torrent-folder") == 0) { gtk_tree_selection_selected_foreach (data->sel, open_folder_foreach, data->core); } - else if (!g_strcmp0 (action_name, "show-torrent-properties")) + else if (g_strcmp0 (action_name, "show-torrent-properties") == 0) { show_details_dialog_for_selected_torrents (data); } - else if (!g_strcmp0 (action_name, "new-torrent")) + else if (g_strcmp0 (action_name, "new-torrent") == 0) { GtkWidget * w = gtr_torrent_creation_dialog_new (data->wind, data->core); gtk_widget_show (w); } - else if (!g_strcmp0 (action_name, "remove-torrent")) + else if (g_strcmp0 (action_name, "remove-torrent") == 0) { remove_selected (data, FALSE); } - else if (!g_strcmp0 (action_name, "delete-torrent")) + else if (g_strcmp0 (action_name, "delete-torrent") == 0) { remove_selected (data, TRUE); } - else if (!g_strcmp0 (action_name, "quit")) + else if (g_strcmp0 (action_name, "quit") == 0) { on_app_exit (data); } - else if (!g_strcmp0 (action_name, "select-all")) + else if (g_strcmp0 (action_name, "select-all") == 0) { gtk_tree_selection_select_all (data->sel); } - else if (!g_strcmp0 (action_name, "deselect-all")) + else if (g_strcmp0 (action_name, "deselect-all") == 0) { gtk_tree_selection_unselect_all (data->sel); } - else if (!g_strcmp0 (action_name, "edit-preferences")) + else if (g_strcmp0 (action_name, "edit-preferences") == 0) { if (NULL == data->prefs) { @@ -1630,7 +1630,7 @@ gtr_actions_handler (const char * action_name, gpointer user_data) } gtr_window_present (GTK_WINDOW (data->prefs)); } - else if (!g_strcmp0 (action_name, "toggle-message-log")) + else if (g_strcmp0 (action_name, "toggle-message-log") == 0) { if (!data->msgwin) { @@ -1645,19 +1645,19 @@ gtr_actions_handler (const char * action_name, gpointer user_data) data->msgwin = NULL; } } - else if (!g_strcmp0 (action_name, "show-about-dialog")) + else if (g_strcmp0 (action_name, "show-about-dialog") == 0) { show_about_dialog (data->wind); } - else if (!g_strcmp0 (action_name, "help")) + else if (g_strcmp0 (action_name, "help") == 0) { gtr_open_uri (gtr_get_help_uri ()); } - else if (!g_strcmp0 (action_name, "toggle-main-window")) + else if (g_strcmp0 (action_name, "toggle-main-window") == 0) { toggleMainWindow (data); } - else if (!g_strcmp0 (action_name, "present-main-window")) + else if (g_strcmp0 (action_name, "present-main-window") == 0) { presentMainWindow (data); } diff --git a/gtk/tr-core.c b/gtk/tr-core.c index 51994b6a8..e18663875 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -618,21 +618,21 @@ core_set_sort_mode (TrCore * core, const char * mode, gboolean is_reversed) GtkSortType type = is_reversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING; GtkTreeSortable * sortable = GTK_TREE_SORTABLE (gtr_core_model (core)); - if (!g_strcmp0 (mode, "sort-by-activity")) + if (g_strcmp0 (mode, "sort-by-activity") == 0) sort_func = compare_by_activity; - else if (!g_strcmp0 (mode, "sort-by-age")) + else if (g_strcmp0 (mode, "sort-by-age") == 0) sort_func = compare_by_age; - else if (!g_strcmp0 (mode, "sort-by-progress")) + else if (g_strcmp0 (mode, "sort-by-progress") == 0) sort_func = compare_by_progress; - else if (!g_strcmp0 (mode, "sort-by-queue")) + else if (g_strcmp0 (mode, "sort-by-queue") == 0) sort_func = compare_by_queue; - else if (!g_strcmp0 (mode, "sort-by-time-left")) + else if (g_strcmp0 (mode, "sort-by-time-left") == 0) sort_func = compare_by_eta; - else if (!g_strcmp0 (mode, "sort-by-ratio")) + else if (g_strcmp0 (mode, "sort-by-ratio") == 0) sort_func = compare_by_ratio; - else if (!g_strcmp0 (mode, "sort-by-state")) + else if (g_strcmp0 (mode, "sort-by-state") == 0) sort_func = compare_by_state; - else if (!g_strcmp0 (mode, "sort-by-size")) + else if (g_strcmp0 (mode, "sort-by-size") == 0) sort_func = compare_by_size; else { sort_func = compare_by_name; @@ -1665,7 +1665,7 @@ core_commit_prefs_change (TrCore * core, const tr_quark key) void gtr_core_set_pref (TrCore * self, const tr_quark key, const char * newval) { - if (g_strcmp0 (newval, gtr_pref_string_get (key))) + if (g_strcmp0 (newval, gtr_pref_string_get (key)) != 0) { gtr_pref_string_set (key, newval); core_commit_prefs_change (self, key); diff --git a/gtk/tr-window.c b/gtk/tr-window.c index a179e3e71..f08967459 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -664,7 +664,7 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core) const char * val = stats_modes[i].val; w = gtk_radio_menu_item_new_with_label (l, _ (stats_modes[i].i18n)); l = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w)); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), !g_strcmp0 (val, pch)); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), g_strcmp0 (val, pch) == 0); g_object_set_data (G_OBJECT (w), STATS_MODE, (gpointer)stats_modes[i].val); g_signal_connect (w, "toggled", G_CALLBACK (status_menu_toggled_cb), p); gtk_menu_shell_append (GTK_MENU_SHELL (menu), w); @@ -797,13 +797,13 @@ updateStats (PrivateData * p) /* update the stats */ pch = gtr_pref_string_get (TR_KEY_statusbar_stats); - if (!g_strcmp0 (pch, "session-ratio")) + if (g_strcmp0 (pch, "session-ratio") == 0) { tr_sessionGetStats (session, &stats); tr_strlratio (ratio, stats.ratio, sizeof (ratio)); g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio); } - else if (!g_strcmp0 (pch, "session-transfer")) + else if (g_strcmp0 (pch, "session-transfer") == 0) { tr_sessionGetStats (session, &stats); tr_strlsize (up, stats.uploadedBytes, sizeof (up)); @@ -814,7 +814,7 @@ updateStats (PrivateData * p) g_snprintf (buf, sizeof (buf), Q_("Down: %1$s, Up: %2$s"), down, up); } - else if (!g_strcmp0 (pch, "total-transfer")) + else if (g_strcmp0 (pch, "total-transfer") == 0) { tr_sessionGetCumulativeStats (session, &stats); tr_strlsize (up, stats.uploadedBytes, sizeof (up)); diff --git a/gtk/util.c b/gtk/util.c index d1ed11e0b..2df5960f2 100644 --- a/gtk/util.c +++ b/gtk/util.c @@ -626,7 +626,7 @@ gtr_label_set_text (GtkLabel * lb, const char * newstr) { const char * oldstr = gtk_label_get_text (lb); - if (g_strcmp0 (oldstr, newstr)) + if (g_strcmp0 (oldstr, newstr) != 0) gtk_label_set_text (lb, newstr); } diff --git a/libtransmission/announcer-http.c b/libtransmission/announcer-http.c index 50cde0070..cb3ad56c5 100644 --- a/libtransmission/announcer-http.c +++ b/libtransmission/announcer-http.c @@ -407,7 +407,7 @@ on_scrape_done (tr_session * session, for (j=0; jrow_count; ++j) { struct tr_scrape_response_row * row = &response->rows[j]; - if (!memcmp (tr_quark_get_string(key,NULL), row->info_hash, SHA_DIGEST_LENGTH)) + if (memcmp (tr_quark_get_string (key, NULL), row->info_hash, SHA_DIGEST_LENGTH) == 0) { if (tr_variantDictFindInt (val, TR_KEY_complete, &intVal)) row->seeders = intVal; diff --git a/libtransmission/announcer-udp.c b/libtransmission/announcer-udp.c index 3b7c41341..1a8bf7c87 100644 --- a/libtransmission/announcer-udp.c +++ b/libtransmission/announcer-udp.c @@ -769,7 +769,7 @@ tau_session_get_tracker (struct tr_announcer_udp * tau, const char * url) key = tr_strdup_printf ("%s:%d", host, port); for (i=0, n=tr_ptrArraySize (&tau->trackers); !tracker && itrackers, i); - if (!tr_strcmp0 (tmp->key, key)) + if (tr_strcmp0 (tmp->key, key) == 0) tracker = tmp; } diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index eeffbb81e..b11d17ceb 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -123,7 +123,7 @@ compareStops (const void * va, const void * vb) return i; /* secondary key: the torrent's info_hash */ - if ((i = memcmp (a->info_hash, b->info_hash, SHA_DIGEST_LENGTH))) + if ((i = memcmp (a->info_hash, b->info_hash, SHA_DIGEST_LENGTH)) != 0) return i; /* tertiary key: the tracker's announec url */ @@ -591,9 +591,9 @@ filter_trackers (tr_tracker_info * input, int input_count, int * setme_count) */ for (j=0, jn=n; !is_duplicate && jpeer_id); #endif - if (!memcmp (request->url, "http", 4)) + if (memcmp (request->url, "http", 4) == 0) tr_tracker_http_announce (session, request, callback, callback_data); - else if (!memcmp (request->url, "udp://", 6)) + else if (memcmp (request->url, "udp://", 6) == 0) tr_tracker_udp_announce (session, request, callback, callback_data); else tr_logAddError ("Unsupported url: %s", request->url); @@ -1298,7 +1298,7 @@ find_tier (tr_torrent * tor, const char * scrape) for (i=0; tt && itier_count; ++i) { const tr_tracker * const tracker = tt->tiers[i].currentTracker; - if (tracker && !tr_strcmp0 (scrape, tracker->scrape)) + if (tracker != NULL && tr_strcmp0 (scrape, tracker->scrape) == 0) return &tt->tiers[i]; } @@ -1399,9 +1399,9 @@ scrape_request_delegate (tr_announcer * announcer, { tr_session * session = announcer->session; - if (!memcmp (request->url, "http", 4)) + if (memcmp (request->url, "http", 4) == 0) tr_tracker_http_scrape (session, request, callback, callback_data); - else if (!memcmp (request->url, "udp://", 6)) + else if (memcmp (request->url, "udp://", 6) == 0) tr_tracker_udp_scrape (session, request, callback, callback_data); else tr_logAddError ("Unsupported url: %s", request->url); @@ -1432,7 +1432,7 @@ multiscrape (tr_announcer * announcer, tr_ptrArray * tiers) if (req->info_hash_count >= TR_MULTISCRAPE_MAX) continue; - if (tr_strcmp0 (req->url, url)) + if (tr_strcmp0 (req->url, url) != 0) continue; memcpy (req->info_hash[req->info_hash_count++], hash, SHA_DIGEST_LENGTH); @@ -1713,7 +1713,7 @@ copy_tier_attributes_impl (struct tr_tier * tgt, int trackerIndex, const tr_tier /* sanity clause */ assert (trackerIndex < tgt->tracker_count); - assert (!tr_strcmp0 (tgt->trackers[trackerIndex].announce, src->currentTracker->announce)); + assert (tr_strcmp0 (tgt->trackers[trackerIndex].announce, src->currentTracker->announce) == 0); /* bitwise copy will handle most of tr_tier's fields... */ *tgt = *src; @@ -1742,7 +1742,7 @@ copy_tier_attributes (struct tr_torrent_tiers * tt, const tr_tier * src) /* find a tier (if any) which has a match for src->currentTracker */ for (i=0; !found && itier_count; ++i) for (j=0; !found && jtiers[i].tracker_count; ++j) - if ((found = !tr_strcmp0 (src->currentTracker->announce, tt->tiers[i].trackers[j].announce))) + if ((found = tr_strcmp0 (src->currentTracker->announce, tt->tiers[i].trackers[j].announce) == 0)) copy_tier_attributes_impl (&tt->tiers[i], j, src); } diff --git a/libtransmission/clients.c b/libtransmission/clients.c index 6a4d49143..cd7015490 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -113,17 +113,17 @@ isMainlineStyle (const uint8_t * peer_id) static bool decodeBitCometClient (char * buf, size_t buflen, const uint8_t * id) { - int is_bitlord; + bool is_bitlord; int major, minor; const char * name; const char * mod = NULL; - if (!memcmp (id, "exbc", 4)) mod = ""; - else if (!memcmp (id, "FUTB", 4)) mod = " (Solidox Mod) "; - else if (!memcmp (id, "xUTB", 4)) mod = " (Mod 2) "; + if (memcmp (id, "exbc", 4) == 0) mod = ""; + else if (memcmp (id, "FUTB", 4) == 0) mod = " (Solidox Mod) "; + else if (memcmp (id, "xUTB", 4) == 0) mod = " (Mod 2) "; else return false; - is_bitlord = !memcmp (id+6, "LORD", 4); + is_bitlord = memcmp (id+6, "LORD", 4) == 0; name = (is_bitlord) ? "BitLord " : "BitComet "; major = id[4]; minor = id[5]; @@ -153,38 +153,38 @@ tr_clientForId (char * buf, size_t buflen, const void * id_in) /* Azureus-style */ if (id[0] == '-' && id[7] == '-') { - if (!memcmp (id+1, "TR", 2)) + if (memcmp (id+1, "TR", 2) == 0) { - if (!memcmp (id+3, "000", 3)) /* very old client style: -TR0006- is 0.6 */ + if (memcmp (id+3, "000", 3) == 0) /* very old client style: -TR0006- is 0.6 */ tr_snprintf (buf, buflen, "Transmission 0.%c", id[6]); - else if (!memcmp (id+3, "00", 2)) /* previous client style: -TR0072- is 0.72 */ + else if (memcmp (id+3, "00", 2) == 0) /* previous client style: -TR0072- is 0.72 */ tr_snprintf (buf, buflen, "Transmission 0.%02d", strint (id+5,2)); else /* current client style: -TR111Z- is 1.11+ */ tr_snprintf (buf, buflen, "Transmission %d.%02d%s", strint (id+3,1), strint (id+4,2), id[6]=='Z' || id[6]=='X' ? "+" : ""); } - else if (!memcmp (id+1, "UT", 2)) + else if (memcmp (id+1, "UT", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,1), getMnemonicEnd (id[6])); } - else if (!memcmp (id+1, "BT", 2)) + else if (memcmp (id+1, "BT", 2) == 0) { tr_snprintf (buf, buflen, "BitTorrent %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,1), getMnemonicEnd (id[6])); } - else if (!memcmp (id+1, "UM", 2)) + else if (memcmp (id+1, "UM", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent Mac %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,1), getMnemonicEnd (id[6])); } - else if (!memcmp (id+1, "UE", 2)) + else if (memcmp (id+1, "UE", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent Embedded %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,1), getMnemonicEnd (id[6])); } - else if (!memcmp (id+1, "AZ", 2)) + else if (memcmp (id+1, "AZ", 2) == 0) { if (id[3] > '3' || (id[3] == '3' && id[4] >= '1')) /* Vuze starts at version 3.1.0.0 */ four_digits (buf, buflen, "Vuze", id+3); @@ -192,7 +192,7 @@ tr_clientForId (char * buf, size_t buflen, const void * id_in) four_digits (buf, buflen, "Azureus", id+3); } - else if (!memcmp (id+1, "KT", 2)) + else if (memcmp (id+1, "KT", 2) == 0) { if (id[5] == 'D') tr_snprintf (buf, buflen, "KTorrent %d.%d Dev %d", charint (id[3]), charint (id[4]), charint (id[6])); @@ -202,108 +202,108 @@ tr_clientForId (char * buf, size_t buflen, const void * id_in) three_digits (buf, buflen, "KTorrent", id+3); } - else if (!memcmp (id+1, "AG", 2)) four_digits (buf, buflen, "Ares", id+3); - else if (!memcmp (id+1, "AR", 2)) four_digits (buf, buflen, "Arctic", id+3); - else if (!memcmp (id+1, "AT", 2)) four_digits (buf, buflen, "Artemis", id+3); - else if (!memcmp (id+1, "AV", 2)) four_digits (buf, buflen, "Avicora", id+3); - else if (!memcmp (id+1, "BB", 2)) four_digits (buf, buflen, "BitBuddy", id+3); - else if (!memcmp (id+1, "BE", 2)) four_digits (buf, buflen, "BitTorrent SDK", id+3); - else if (!memcmp (id+1, "BG", 2)) four_digits (buf, buflen, "BTGetit", id+3); - else if (!memcmp (id+1, "BH", 2)) four_digits (buf, buflen, "BitZilla", id+3); - else if (!memcmp (id+1, "BM", 2)) four_digits (buf, buflen, "BitMagnet", id+3); - else if (!memcmp (id+1, "BP", 2)) four_digits (buf, buflen, "BitTorrent Pro (Azureus + Spyware)", id+3); - else if (!memcmp (id+1, "BX", 2)) four_digits (buf, buflen, "BittorrentX", id+3); - else if (!memcmp (id+1, "bk", 2)) four_digits (buf, buflen, "BitKitten (libtorrent)", id+3); - else if (!memcmp (id+1, "BS", 2)) four_digits (buf, buflen, "BTSlave", id+3); - else if (!memcmp (id+1, "BW", 2)) four_digits (buf, buflen, "BitWombat", id+3); - else if (!memcmp (id+1, "BX", 2)) four_digits (buf, buflen, "BittorrentX", id+3); - else if (!memcmp (id+1, "EB", 2)) four_digits (buf, buflen, "EBit", id+3); - else if (!memcmp (id+1, "DE", 2)) four_digits (buf, buflen, "Deluge", id+3); - else if (!memcmp (id+1, "DP", 2)) four_digits (buf, buflen, "Propogate Data Client", id+3); - else if (!memcmp (id+1, "FC", 2)) four_digits (buf, buflen, "FileCroc", id+3); - else if (!memcmp (id+1, "FT", 2)) four_digits (buf, buflen, "FoxTorrent/RedSwoosh", id+3); - else if (!memcmp (id+1, "GR", 2)) four_digits (buf, buflen, "GetRight", id+3); - else if (!memcmp (id+1, "GS", 2)) four_digits (buf, buflen, "GSTorrent", id+3); - else if (!memcmp (id+1, "HK", 2)) four_digits (buf, buflen, "Hekate", id+3); - else if (!memcmp (id+1, "HN", 2)) four_digits (buf, buflen, "Hydranode", id+3); - else if (!memcmp (id+1, "KG", 2)) four_digits (buf, buflen, "KGet", id+3); - else if (!memcmp (id+1, "LC", 2)) four_digits (buf, buflen, "LeechCraft", id+3); - else if (!memcmp (id+1, "LH", 2)) four_digits (buf, buflen, "LH-ABC", id+3); - else if (!memcmp (id+1, "NX", 2)) four_digits (buf, buflen, "Net Transport", id+3); - else if (!memcmp (id+1, "MK", 2)) four_digits (buf, buflen, "Meerkat", id+3); - else if (!memcmp (id+1, "MO", 2)) four_digits (buf, buflen, "MonoTorrent", id+3); - else if (!memcmp (id+1, "MR", 2)) four_digits (buf, buflen, "Miro", id+3); - else if (!memcmp (id+1, "MT", 2)) four_digits (buf, buflen, "Moonlight", id+3); - else if (!memcmp (id+1, "OS", 2)) four_digits (buf, buflen, "OneSwarm", id+3); - else if (!memcmp (id+1, "OT", 2)) four_digits (buf, buflen, "OmegaTorrent", id+3); - else if (!memcmp (id+1, "PD", 2)) four_digits (buf, buflen, "Pando", id+3); - else if (!memcmp (id+1, "QD", 2)) four_digits (buf, buflen, "QQDownload", id+3); - else if (!memcmp (id+1, "RS", 2)) four_digits (buf, buflen, "Rufus", id+3); - else if (!memcmp (id+1, "RT", 2)) four_digits (buf, buflen, "Retriever", id+3); - else if (!memcmp (id+1, "RZ", 2)) four_digits (buf, buflen, "RezTorrent", id+3); - else if (!memcmp (id+1, "SD", 2)) four_digits (buf, buflen, "Thunder", id+3); - else if (!memcmp (id+1, "SM", 2)) four_digits (buf, buflen, "SoMud", id+3); - else if (!memcmp (id+1, "SS", 2)) four_digits (buf, buflen, "SwarmScope", id+3); - else if (!memcmp (id+1, "ST", 2)) four_digits (buf, buflen, "SymTorrent", id+3); - else if (!memcmp (id+1, "SZ", 2)) four_digits (buf, buflen, "Shareaza", id+3); - else if (!memcmp (id+1, "S~", 2)) four_digits (buf, buflen, "Shareaza", id+3); - else if (!memcmp (id+1, "st", 2)) four_digits (buf, buflen, "SharkTorrent", id+3); - else if (!memcmp (id+1, "TN", 2)) four_digits (buf, buflen, "Torrent .NET", id+3); - else if (!memcmp (id+1, "TS", 2)) four_digits (buf, buflen, "TorrentStorm", id+3); - else if (!memcmp (id+1, "TT", 2)) four_digits (buf, buflen, "TuoTu", id+3); - else if (!memcmp (id+1, "UL", 2)) four_digits (buf, buflen, "uLeecher!", id+3); - else if (!memcmp (id+1, "VG", 2)) four_digits (buf, buflen, "Vagaa", id+3); - else if (!memcmp (id+1, "WT", 2)) four_digits (buf, buflen, "BitLet", id+3); - else if (!memcmp (id+1, "WY", 2)) four_digits (buf, buflen, "FireTorrent", id+3); - else if (!memcmp (id+1, "XL", 2)) four_digits (buf, buflen, "Xunlei", id+3); - else if (!memcmp (id+1, "XS", 2)) four_digits (buf, buflen, "XSwifter", id+3); - else if (!memcmp (id+1, "XT", 2)) four_digits (buf, buflen, "XanTorrent", id+3); - else if (!memcmp (id+1, "XX", 2)) four_digits (buf, buflen, "Xtorrent", id+3); - else if (!memcmp (id+1, "ZT", 2)) four_digits (buf, buflen, "Zip Torrent", id+3); - else if (!memcmp (id+1, "ZO", 2)) four_digits (buf, buflen, "Zona", id+3); - - else if (!memcmp (id+1, "AG", 2)) three_digits (buf, buflen, "Ares", id+3); - else if (!memcmp (id+1, "A~", 2)) three_digits (buf, buflen, "Ares", id+3); - else if (!memcmp (id+1, "ES", 2)) three_digits (buf, buflen, "Electric Sheep", id+3); - else if (!memcmp (id+1, "HL", 2)) three_digits (buf, buflen, "Halite", id+3); - else if (!memcmp (id+1, "LT", 2)) three_digits (buf, buflen, "libtorrent (Rasterbar)", id+3); - else if (!memcmp (id+1, "lt", 2)) three_digits (buf, buflen, "libTorrent (Rakshasa)", id+3); - else if (!memcmp (id+1, "MP", 2)) three_digits (buf, buflen, "MooPolice", id+3); - else if (!memcmp (id+1, "pb", 2)) three_digits (buf, buflen, "pbTorrent", id+3); - else if (!memcmp (id+1, "TT", 2)) three_digits (buf, buflen, "TuoTu", id+3); - else if (!memcmp (id+1, "qB", 2)) three_digits (buf, buflen, "qBittorrent", id+3); - - else if (!memcmp (id+1, "AX", 2)) two_major_two_minor (buf, buflen, "BitPump", id+3); - else if (!memcmp (id+1, "BC", 2)) two_major_two_minor (buf, buflen, "BitComet", id+3); - else if (!memcmp (id+1, "CD", 2)) two_major_two_minor (buf, buflen, "Enhanced CTorrent", id+3); - else if (!memcmp (id+1, "LP", 2)) two_major_two_minor (buf, buflen, "Lphant", id+3); - - else if (!memcmp (id+1, "BF", 2)) no_version (buf, buflen, "BitFlu"); - else if (!memcmp (id+1, "LW", 2)) no_version (buf, buflen, "LimeWire"); - - else if (!memcmp (id+1, "BB", 2)) + else if (memcmp (id+1, "AG", 2) == 0) four_digits (buf, buflen, "Ares", id+3); + else if (memcmp (id+1, "AR", 2) == 0) four_digits (buf, buflen, "Arctic", id+3); + else if (memcmp (id+1, "AT", 2) == 0) four_digits (buf, buflen, "Artemis", id+3); + else if (memcmp (id+1, "AV", 2) == 0) four_digits (buf, buflen, "Avicora", id+3); + else if (memcmp (id+1, "BB", 2) == 0) four_digits (buf, buflen, "BitBuddy", id+3); + else if (memcmp (id+1, "BE", 2) == 0) four_digits (buf, buflen, "BitTorrent SDK", id+3); + else if (memcmp (id+1, "BG", 2) == 0) four_digits (buf, buflen, "BTGetit", id+3); + else if (memcmp (id+1, "BH", 2) == 0) four_digits (buf, buflen, "BitZilla", id+3); + else if (memcmp (id+1, "BM", 2) == 0) four_digits (buf, buflen, "BitMagnet", id+3); + else if (memcmp (id+1, "BP", 2) == 0) four_digits (buf, buflen, "BitTorrent Pro (Azureus + Spyware)", id+3); + else if (memcmp (id+1, "BX", 2) == 0) four_digits (buf, buflen, "BittorrentX", id+3); + else if (memcmp (id+1, "bk", 2) == 0) four_digits (buf, buflen, "BitKitten (libtorrent)", id+3); + else if (memcmp (id+1, "BS", 2) == 0) four_digits (buf, buflen, "BTSlave", id+3); + else if (memcmp (id+1, "BW", 2) == 0) four_digits (buf, buflen, "BitWombat", id+3); + else if (memcmp (id+1, "BX", 2) == 0) four_digits (buf, buflen, "BittorrentX", id+3); + else if (memcmp (id+1, "EB", 2) == 0) four_digits (buf, buflen, "EBit", id+3); + else if (memcmp (id+1, "DE", 2) == 0) four_digits (buf, buflen, "Deluge", id+3); + else if (memcmp (id+1, "DP", 2) == 0) four_digits (buf, buflen, "Propogate Data Client", id+3); + else if (memcmp (id+1, "FC", 2) == 0) four_digits (buf, buflen, "FileCroc", id+3); + else if (memcmp (id+1, "FT", 2) == 0) four_digits (buf, buflen, "FoxTorrent/RedSwoosh", id+3); + else if (memcmp (id+1, "GR", 2) == 0) four_digits (buf, buflen, "GetRight", id+3); + else if (memcmp (id+1, "GS", 2) == 0) four_digits (buf, buflen, "GSTorrent", id+3); + else if (memcmp (id+1, "HK", 2) == 0) four_digits (buf, buflen, "Hekate", id+3); + else if (memcmp (id+1, "HN", 2) == 0) four_digits (buf, buflen, "Hydranode", id+3); + else if (memcmp (id+1, "KG", 2) == 0) four_digits (buf, buflen, "KGet", id+3); + else if (memcmp (id+1, "LC", 2) == 0) four_digits (buf, buflen, "LeechCraft", id+3); + else if (memcmp (id+1, "LH", 2) == 0) four_digits (buf, buflen, "LH-ABC", id+3); + else if (memcmp (id+1, "NX", 2) == 0) four_digits (buf, buflen, "Net Transport", id+3); + else if (memcmp (id+1, "MK", 2) == 0) four_digits (buf, buflen, "Meerkat", id+3); + else if (memcmp (id+1, "MO", 2) == 0) four_digits (buf, buflen, "MonoTorrent", id+3); + else if (memcmp (id+1, "MR", 2) == 0) four_digits (buf, buflen, "Miro", id+3); + else if (memcmp (id+1, "MT", 2) == 0) four_digits (buf, buflen, "Moonlight", id+3); + else if (memcmp (id+1, "OS", 2) == 0) four_digits (buf, buflen, "OneSwarm", id+3); + else if (memcmp (id+1, "OT", 2) == 0) four_digits (buf, buflen, "OmegaTorrent", id+3); + else if (memcmp (id+1, "PD", 2) == 0) four_digits (buf, buflen, "Pando", id+3); + else if (memcmp (id+1, "QD", 2) == 0) four_digits (buf, buflen, "QQDownload", id+3); + else if (memcmp (id+1, "RS", 2) == 0) four_digits (buf, buflen, "Rufus", id+3); + else if (memcmp (id+1, "RT", 2) == 0) four_digits (buf, buflen, "Retriever", id+3); + else if (memcmp (id+1, "RZ", 2) == 0) four_digits (buf, buflen, "RezTorrent", id+3); + else if (memcmp (id+1, "SD", 2) == 0) four_digits (buf, buflen, "Thunder", id+3); + else if (memcmp (id+1, "SM", 2) == 0) four_digits (buf, buflen, "SoMud", id+3); + else if (memcmp (id+1, "SS", 2) == 0) four_digits (buf, buflen, "SwarmScope", id+3); + else if (memcmp (id+1, "ST", 2) == 0) four_digits (buf, buflen, "SymTorrent", id+3); + else if (memcmp (id+1, "SZ", 2) == 0) four_digits (buf, buflen, "Shareaza", id+3); + else if (memcmp (id+1, "S~", 2) == 0) four_digits (buf, buflen, "Shareaza", id+3); + else if (memcmp (id+1, "st", 2) == 0) four_digits (buf, buflen, "SharkTorrent", id+3); + else if (memcmp (id+1, "TN", 2) == 0) four_digits (buf, buflen, "Torrent .NET", id+3); + else if (memcmp (id+1, "TS", 2) == 0) four_digits (buf, buflen, "TorrentStorm", id+3); + else if (memcmp (id+1, "TT", 2) == 0) four_digits (buf, buflen, "TuoTu", id+3); + else if (memcmp (id+1, "UL", 2) == 0) four_digits (buf, buflen, "uLeecher!", id+3); + else if (memcmp (id+1, "VG", 2) == 0) four_digits (buf, buflen, "Vagaa", id+3); + else if (memcmp (id+1, "WT", 2) == 0) four_digits (buf, buflen, "BitLet", id+3); + else if (memcmp (id+1, "WY", 2) == 0) four_digits (buf, buflen, "FireTorrent", id+3); + else if (memcmp (id+1, "XL", 2) == 0) four_digits (buf, buflen, "Xunlei", id+3); + else if (memcmp (id+1, "XS", 2) == 0) four_digits (buf, buflen, "XSwifter", id+3); + else if (memcmp (id+1, "XT", 2) == 0) four_digits (buf, buflen, "XanTorrent", id+3); + else if (memcmp (id+1, "XX", 2) == 0) four_digits (buf, buflen, "Xtorrent", id+3); + else if (memcmp (id+1, "ZT", 2) == 0) four_digits (buf, buflen, "Zip Torrent", id+3); + else if (memcmp (id+1, "ZO", 2) == 0) four_digits (buf, buflen, "Zona", id+3); + + else if (memcmp (id+1, "AG", 2) == 0) three_digits (buf, buflen, "Ares", id+3); + else if (memcmp (id+1, "A~", 2) == 0) three_digits (buf, buflen, "Ares", id+3); + else if (memcmp (id+1, "ES", 2) == 0) three_digits (buf, buflen, "Electric Sheep", id+3); + else if (memcmp (id+1, "HL", 2) == 0) three_digits (buf, buflen, "Halite", id+3); + else if (memcmp (id+1, "LT", 2) == 0) three_digits (buf, buflen, "libtorrent (Rasterbar)", id+3); + else if (memcmp (id+1, "lt", 2) == 0) three_digits (buf, buflen, "libTorrent (Rakshasa)", id+3); + else if (memcmp (id+1, "MP", 2) == 0) three_digits (buf, buflen, "MooPolice", id+3); + else if (memcmp (id+1, "pb", 2) == 0) three_digits (buf, buflen, "pbTorrent", id+3); + else if (memcmp (id+1, "TT", 2) == 0) three_digits (buf, buflen, "TuoTu", id+3); + else if (memcmp (id+1, "qB", 2) == 0) three_digits (buf, buflen, "qBittorrent", id+3); + + else if (memcmp (id+1, "AX", 2) == 0) two_major_two_minor (buf, buflen, "BitPump", id+3); + else if (memcmp (id+1, "BC", 2) == 0) two_major_two_minor (buf, buflen, "BitComet", id+3); + else if (memcmp (id+1, "CD", 2) == 0) two_major_two_minor (buf, buflen, "Enhanced CTorrent", id+3); + else if (memcmp (id+1, "LP", 2) == 0) two_major_two_minor (buf, buflen, "Lphant", id+3); + + else if (memcmp (id+1, "BF", 2) == 0) no_version (buf, buflen, "BitFlu"); + else if (memcmp (id+1, "LW", 2) == 0) no_version (buf, buflen, "LimeWire"); + + else if (memcmp (id+1, "BB", 2) == 0) { tr_snprintf (buf, buflen, "BitBuddy %c.%c%c%c", id[3], id[4], id[5], id[6]); } - else if (!memcmp (id+1, "BR", 2)) + else if (memcmp (id+1, "BR", 2) == 0) { tr_snprintf (buf, buflen, "BitRocket %c.%c (%c%c)", id[3], id[4], id[5], id[6]); } - else if (!memcmp (id+1, "CT", 2)) + else if (memcmp (id+1, "CT", 2) == 0) { tr_snprintf (buf, buflen, "CTorrent %d.%d.%02d", charint (id[3]), charint (id[4]), strint (id+5,2)); } - else if (!memcmp (id+1, "XC", 2) || !memcmp (id+1, "XX", 2)) + else if (memcmp (id+1, "XC", 2) == 0 || memcmp (id+1, "XX", 2) == 0) { tr_snprintf (buf, buflen, "Xtorrent %d.%d (%d)", charint (id[3]), charint (id[4]), strint (id+5,2)); } - else if (!memcmp (id+1, "BOW", 3)) + else if (memcmp (id+1, "BOW", 3) == 0) { - if (!memcmp (&id[4], "A0B", 3)) tr_snprintf (buf, buflen, "Bits on Wheels 1.0.5"); - else if (!memcmp (&id[4], "A0C", 3)) tr_snprintf (buf, buflen, "Bits on Wheels 1.0.6"); + if (memcmp (&id[4], "A0B", 3) == 0) tr_snprintf (buf, buflen, "Bits on Wheels 1.0.5"); + else if (memcmp (&id[4], "A0C", 3) == 0) tr_snprintf (buf, buflen, "Bits on Wheels 1.0.6"); else tr_snprintf (buf, buflen, "Bits on Wheels %c.%c.%c", id[4], id[5], id[5]); } - else if (!memcmp (id+1, "MG", 2)) + else if (memcmp (id+1, "MG", 2) == 0) { tr_snprintf (buf, buflen, "MediaGet %d.%02d", charint (id[3]), charint (id[4])); } @@ -315,17 +315,17 @@ tr_clientForId (char * buf, size_t buflen, const void * id_in) /* uTorrent will replace the trailing dash with an extra digit for longer version numbers */ if (id[0] == '-') { - if (!memcmp (id+1, "UT", 2)) + if (memcmp (id+1, "UT", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,2), getMnemonicEnd (id[7])); } - else if (!memcmp (id+1, "UM", 2)) + else if (memcmp (id+1, "UM", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent Mac %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,2), getMnemonicEnd (id[7])); } - else if (!memcmp (id+1, "UE", 2)) + else if (memcmp (id+1, "UE", 2) == 0) { tr_snprintf (buf, buflen, "\xc2\xb5Torrent Embedded %d.%d.%d%s", strint (id+3,1), strint (id+4,1), strint (id+5,2), getMnemonicEnd (id[7])); @@ -347,76 +347,76 @@ tr_clientForId (char * buf, size_t buflen, const void * id_in) return buf; /* Clients with no version */ - if (!memcmp (id, "AZ2500BT", 8)) no_version (buf, buflen, "BitTyrant (Azureus Mod)"); - else if (!memcmp (id, "LIME", 4)) no_version (buf, buflen, "Limewire"); - else if (!memcmp (id, "martini", 7)) no_version (buf, buflen, "Martini Man"); - else if (!memcmp (id, "Pando", 5)) no_version (buf, buflen, "Pando"); - else if (!memcmp (id, "a00---0", 7)) no_version (buf, buflen, "Swarmy"); - else if (!memcmp (id, "a02---0", 7)) no_version (buf, buflen, "Swarmy"); - else if (!memcmp (id, "-G3", 3)) no_version (buf, buflen, "G3 Torrent"); - else if (!memcmp (id, "10-------", 9)) no_version (buf, buflen, "JVtorrent"); - else if (!memcmp (id, "346-", 4)) no_version (buf, buflen, "TorrentTopia"); - else if (!memcmp (id, "eX", 2)) no_version (buf, buflen, "eXeem"); - else if (!memcmp (id, "aria2-", 6)) no_version (buf, buflen, "aria2"); - else if (!memcmp (id, "-WT-", 4)) no_version (buf, buflen, "BitLet"); - else if (!memcmp (id, "-FG", 3)) two_major_two_minor (buf, buflen, "FlashGet", id+3); + if (memcmp (id, "AZ2500BT", 8) == 0) no_version (buf, buflen, "BitTyrant (Azureus Mod)"); + else if (memcmp (id, "LIME", 4) == 0) no_version (buf, buflen, "Limewire"); + else if (memcmp (id, "martini", 7) == 0) no_version (buf, buflen, "Martini Man"); + else if (memcmp (id, "Pando", 5) == 0) no_version (buf, buflen, "Pando"); + else if (memcmp (id, "a00---0", 7) == 0) no_version (buf, buflen, "Swarmy"); + else if (memcmp (id, "a02---0", 7) == 0) no_version (buf, buflen, "Swarmy"); + else if (memcmp (id, "-G3", 3) == 0) no_version (buf, buflen, "G3 Torrent"); + else if (memcmp (id, "10-------", 9) == 0) no_version (buf, buflen, "JVtorrent"); + else if (memcmp (id, "346-", 4) == 0) no_version (buf, buflen, "TorrentTopia"); + else if (memcmp (id, "eX", 2) == 0) no_version (buf, buflen, "eXeem"); + else if (memcmp (id, "aria2-", 6) == 0) no_version (buf, buflen, "aria2"); + else if (memcmp (id, "-WT-", 4) == 0) no_version (buf, buflen, "BitLet"); + else if (memcmp (id, "-FG", 3) == 0) two_major_two_minor (buf, buflen, "FlashGet", id+3); /* Everything else */ - else if (!memcmp (id, "S3", 2) && id[2] == '-' && id[4] == '-' && id[6] == '-') + else if (memcmp (id, "S3", 2) == 0 && id[2] == '-' && id[4] == '-' && id[6] == '-') { tr_snprintf (buf, buflen, "Amazon S3 %c.%c.%c", id[3], id[5], id[7]); } - else if (!memcmp (id, "OP", 2)) + else if (memcmp (id, "OP", 2) == 0) { tr_snprintf (buf, buflen, "Opera (Build %c%c%c%c)", id[2], id[3], id[4], id[5]); } - else if (!memcmp (id, "-ML", 3)) + else if (memcmp (id, "-ML", 3) == 0) { tr_snprintf (buf, buflen, "MLDonkey %c%c%c%c%c", id[3], id[4], id[5], id[6], id[7]); } - else if (!memcmp (id, "DNA", 3)) + else if (memcmp (id, "DNA", 3) == 0) { tr_snprintf (buf, buflen, "BitTorrent DNA %d.%d.%d", strint (id+3,2), strint (id+5,2), strint (id+7,2)); } - else if (!memcmp (id, "Plus", 4)) + else if (memcmp (id, "Plus", 4) == 0) { tr_snprintf (buf, buflen, "Plus! v2 %c.%c%c", id[4], id[5], id[6]); } - else if (!memcmp (id, "XBT", 3)) + else if (memcmp (id, "XBT", 3) == 0) { tr_snprintf (buf, buflen, "XBT Client %c.%c.%c%s", id[3], id[4], id[5], getMnemonicEnd (id[6])); } - else if (!memcmp (id, "Mbrst", 5)) + else if (memcmp (id, "Mbrst", 5) == 0) { tr_snprintf (buf, buflen, "burst! %c.%c.%c", id[5], id[7], id[9]); } - else if (!memcmp (id, "btpd", 4)) + else if (memcmp (id, "btpd", 4) == 0) { tr_snprintf (buf, buflen, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7]); } - else if (!memcmp (id, "BLZ", 3)) + else if (memcmp (id, "BLZ", 3) == 0) { tr_snprintf (buf, buflen, "Blizzard Downloader %d.%d", id[3]+1, id[4]); } - else if (!memcmp (id, "-SP", 3)) + else if (memcmp (id, "-SP", 3) == 0) { three_digits (buf, buflen, "BitSpirit", id+3); } - else if ('\0' == id[0] && !memcmp (id+2, "BS", 2)) + else if ('\0' == id[0] && memcmp (id+2, "BS", 2) == 0) { tr_snprintf (buf, buflen, "BitSpirit %u", (id[1] == 0 ? 1 : id[1])); } - else if (!memcmp (id, "QVOD", 4)) + else if (memcmp (id, "QVOD", 4) == 0) { four_digits (buf, buflen, "QVOD", id+4); } - else if (!memcmp (id, "-NE", 3)) + else if (memcmp (id, "-NE", 3) == 0) { four_digits (buf, buflen, "BT Next Evolution", id+3); } - else if (!memcmp (id, "TIX", 3)) + else if (memcmp (id, "TIX", 3) == 0) { two_major_two_minor (buf, buflen, "Tixati", id+3); } diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 4367fbbca..7dbb24dfd 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -258,7 +258,7 @@ parseHandshake (tr_handshake * handshake, /* confirm the protocol */ tr_peerIoReadBytes (handshake->io, inbuf, name, HANDSHAKE_NAME_LEN); - if (memcmp (name, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN)) + if (memcmp (name, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN) != 0) return HANDSHAKE_ENCRYPTION_WRONG; /* read the reserved bytes */ @@ -268,7 +268,7 @@ parseHandshake (tr_handshake * handshake, tr_peerIoReadBytes (handshake->io, inbuf, hash, sizeof (hash)); assert (tr_peerIoHasTorrentHash (handshake->io)); if (!tr_torrentExists (handshake->session, hash) - || memcmp (hash, tr_peerIoGetTorrentHash (handshake->io), SHA_DIGEST_LENGTH)) + || memcmp (hash, tr_peerIoGetTorrentHash (handshake->io), SHA_DIGEST_LENGTH) != 0) { dbgmsg (handshake, "peer returned the wrong hash. wtf?"); return HANDSHAKE_BAD_TORRENT; @@ -283,7 +283,7 @@ parseHandshake (tr_handshake * handshake, dbgmsg (handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id); tor = tr_torrentFindFromHash (handshake->session, hash); - if (!memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN)) + if (memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN) == 0) { dbgmsg (handshake, "streuth! we've connected to ourselves."); return HANDSHAKE_PEER_IS_SELF; @@ -514,7 +514,7 @@ readVC (tr_handshake * handshake, memcpy (tmp, evbuffer_pullup (inbuf, key_len), key_len); tr_cryptoDecryptInit (handshake->crypto); tr_cryptoDecrypt (handshake->crypto, key_len, tmp, tmp); - if (!memcmp (tmp, key, key_len)) + if (memcmp (tmp, key, key_len) == 0) break; evbuffer_drain (inbuf, 1); @@ -642,7 +642,7 @@ readHandshake (tr_handshake * handshake, assert (pstrlen == 19); tr_peerIoReadBytes (handshake->io, inbuf, pstr, pstrlen); pstr[pstrlen] = '\0'; - if (memcmp (pstr, "BitTorrent protocol", 19)) + if (memcmp (pstr, "BitTorrent protocol", 19) != 0) return tr_handshakeDone (handshake, false); /* reserved bytes */ @@ -675,7 +675,7 @@ readHandshake (tr_handshake * handshake, { assert (tr_peerIoHasTorrentHash (handshake->io)); - if (memcmp (hash, tr_peerIoGetTorrentHash (handshake->io), SHA_DIGEST_LENGTH)) + if (memcmp (hash, tr_peerIoGetTorrentHash (handshake->io), SHA_DIGEST_LENGTH) != 0) { dbgmsg (handshake, "peer returned the wrong hash. wtf?"); return tr_handshakeDone (handshake, false); @@ -721,7 +721,7 @@ readPeerId (tr_handshake * handshake, /* if we've somehow connected to ourselves, don't keep the connection */ tor = tr_torrentFindFromHash (handshake->session, tr_peerIoGetTorrentHash (handshake->io)); - connected_to_self = (tor != NULL) && !memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN); + connected_to_self = (tor != NULL) && memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN) == 0; return tr_handshakeDone (handshake, !connected_to_self); } diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 5f580f5da..5ed54aa60 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -313,5 +313,5 @@ tr_ioTestPiece (tr_torrent * tor, tr_piece_index_t piece) uint8_t hash[SHA_DIGEST_LENGTH]; return recalculateHash (tor, piece, hash) - && !memcmp (hash, tor->info.pieces[piece].hash, SHA_DIGEST_LENGTH); + && memcmp (hash, tor->info.pieces[piece].hash, SHA_DIGEST_LENGTH) == 0; } diff --git a/libtransmission/libtransmission-test.c b/libtransmission/libtransmission-test.c index 492219461..aed179963 100644 --- a/libtransmission/libtransmission-test.c +++ b/libtransmission/libtransmission-test.c @@ -62,7 +62,7 @@ check_condition_impl (const char * file, int line, bool condition) bool check_streq_impl (const char * file, int line, const char * expected, const char * actual) { - const bool pass = !tr_strcmp0 (expected, actual); + const bool pass = tr_strcmp0 (expected, actual) == 0; if (should_print (pass)) { if (pass) diff --git a/libtransmission/magnet.c b/libtransmission/magnet.c index 240560012..d24191e54 100644 --- a/libtransmission/magnet.c +++ b/libtransmission/magnet.c @@ -111,7 +111,7 @@ tr_magnetParse (const char * uri) uint8_t sha1[SHA_DIGEST_LENGTH]; tr_magnet_info * info = NULL; - if ((uri != NULL) && !memcmp (uri, "magnet:?", 8)) + if (uri != NULL && memcmp (uri, "magnet:?", 8) == 0) { const char * walk; @@ -137,7 +137,7 @@ tr_magnetParse (const char * uri) else vallen = strlen (val); - if ((keylen==2) && !memcmp (key, "xt", 2) && val && !memcmp (val, "urn:btih:", 9)) + if (keylen == 2 && memcmp (key, "xt", 2) == 0 && val != NULL && memcmp (val, "urn:btih:", 9) == 0) { const char * hash = val + 9; const size_t hashlen = vallen - 9; @@ -154,19 +154,19 @@ tr_magnetParse (const char * uri) } } - if ((vallen > 0) && (keylen==2) && !memcmp (key, "dn", 2)) + if (vallen > 0 && keylen == 2 && memcmp (key, "dn", 2) == 0) displayName = tr_http_unescape (val, vallen); if ((vallen > 0) && (trCount < MAX_TRACKERS)) { int i; - if ((keylen==2) && !memcmp (key, "tr", 2)) + if (keylen == 2 && memcmp (key, "tr", 2) == 0) tr[trCount++] = tr_http_unescape (val, vallen); else if ((sscanf (key, "tr.%d=", &i) == 1) && (i >= 0)) /* ticket #3341 and #5134 */ tr[trCount++] = tr_http_unescape (val, vallen); } - if ((vallen > 0) && (keylen==2) && !memcmp (key, "ws", 2) && (wsCount < MAX_WEBSEEDS)) + if (vallen > 0 && keylen == 2 && memcmp (key, "ws", 2) == 0 && wsCount < MAX_WEBSEEDS) ws[wsCount++] = tr_http_unescape (val, vallen); walk = next != NULL ? next + 1 : NULL; diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 2c04e4d88..62d71869b 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -225,7 +225,7 @@ tr_convertAnnounceToScrape (const char * announce) * it will be taken as a sign that that tracker doesn't support * the scrape convention. If it does, substitute 'scrape' for * 'announce' to find the scrape page. */ - if (((s = strrchr (announce, '/'))) && !strncmp (++s, "announce", 8)) + if (((s = strrchr (announce, '/')) != NULL) && strncmp (++s, "announce", 8) == 0) { const char * prefix = announce; const size_t prefix_len = s - announce; @@ -240,7 +240,7 @@ tr_convertAnnounceToScrape (const char * announce) assert (walk - scrape == (int)alloc_len); } /* Some torrents with UDP annouce URLs don't have /announce. */ - else if (!strncmp (announce, "udp:", 4)) + else if (strncmp (announce, "udp:", 4) == 0) { scrape = tr_strdup (announce); } diff --git a/libtransmission/platform-quota.c b/libtransmission/platform-quota.c index e7d1f6d4f..46d011dde 100644 --- a/libtransmission/platform-quota.c +++ b/libtransmission/platform-quota.c @@ -87,7 +87,7 @@ getdev (const char * path) return NULL; while (getmntent(fp, &mnt)) - if (!tr_strcmp0 (path, mnt.mnt_mountp)) + if (tr_strcmp0 (path, mnt.mnt_mountp) == 0) break; fclose(fp); return mnt.mnt_special; @@ -99,7 +99,7 @@ getdev (const char * path) return NULL; while ((mnt = getmntent(fp)) != NULL) - if (!tr_strcmp0 (path, mnt->mnt_dir)) + if (tr_strcmp0 (path, mnt->mnt_dir) == 0) break; endmntent(fp); @@ -116,7 +116,7 @@ getdev (const char * path) return NULL; for (i=0; imnt_fsname)) + if (tr_strcmp0 (device, mnt->mnt_fsname) == 0) break; endmntent(fp); @@ -166,7 +166,7 @@ getfstype (const char * device) return NULL; for (i=0; istr, b->str, MIN (a->len, b->len)); - if (!ret && (a->len != b->len)) + if (ret == 0 && a->len != b->len) ret = a->len < b->len ? -1 : 1; return ret; diff --git a/libtransmission/rename-test.c b/libtransmission/rename-test.c index 489ee4a84..cf713873e 100644 --- a/libtransmission/rename-test.c +++ b/libtransmission/rename-test.c @@ -56,8 +56,8 @@ testFileExistsAndConsistsOfThisString (const tr_torrent * tor, tr_file_index_t f contents = tr_loadFile (path, &contents_len, NULL); success = contents != NULL - && (str_len == contents_len) - && (!memcmp (contents, str, contents_len)); + && str_len == contents_len + && memcmp (contents, str, contents_len) == 0; tr_free (contents); tr_free (path); diff --git a/libtransmission/resume.c b/libtransmission/resume.c index c0547e084..57153e976 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -351,7 +351,7 @@ loadName (tr_variant * dict, tr_torrent * tor) { ret = TR_FR_NAME; - if (tr_strcmp0 (tr_torrentName(tor), name)) + if (tr_strcmp0 (tr_torrentName(tor), name) != 0) { tr_free (tor->info.name); tor->info.name = tr_strdup (name); @@ -614,16 +614,16 @@ loadProgress (tr_variant * dict, tr_torrent * tor) if (!tr_variantGetRaw (b, &buf, &buflen)) err = "Invalid value for \"blocks\""; - else if ((buflen == 3) && !memcmp (buf, "all", 3)) + else if (buflen == 3 && memcmp (buf, "all", 3) == 0) tr_bitfieldSetHasAll (&blocks); - else if ((buflen == 4) && !memcmp (buf, "none", 4)) + else if (buflen == 4 && memcmp (buf, "none", 4) == 0) tr_bitfieldSetHasNone (&blocks); else tr_bitfieldSetRaw (&blocks, buf, buflen, true); } else if (tr_variantDictFindStr (prog, TR_KEY_have, &str, NULL)) { - if (!strcmp (str, "all")) + if (strcmp (str, "all") == 0) tr_bitfieldSetHasAll (&blocks); else err = "Invalid value for HAVE"; diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index a3485f3fa..a94e16a9d 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -224,7 +224,7 @@ handle_upload (struct evhttp_request * req, const struct tr_mimepart * p = tr_ptrArrayNth (&parts, i); const char * ours = get_current_session_id (server); const size_t ourlen = strlen (ours); - hasSessionId = ourlen<=p->body_len && !memcmp (p->body, ours, ourlen); + hasSessionId = ourlen <= p->body_len && memcmp (p->body, ours, ourlen) == 0; } if (!hasSessionId) @@ -245,7 +245,7 @@ handle_upload (struct evhttp_request * req, bool have_source = false; char * body = p->body; - if (body_len >= 2 && !memcmp (&body[body_len - 2], "\r\n", 2)) + if (body_len >= 2 && memcmp (&body[body_len - 2], "\r\n", 2) == 0) body_len -= 2; tr_variantInitDict (&top, 2); @@ -310,7 +310,7 @@ mimetype_guess (const char * path) const char * dot = strrchr (path, '.'); for (i = 0; dot && i < TR_N_ELEMENTS (types); ++i) - if (!strcmp (dot + 1, types[i].suffix)) + if (strcmp (dot + 1, types[i].suffix) == 0) return types[i].mime_type; return "application/octet-stream"; @@ -593,7 +593,7 @@ test_session_id (struct tr_rpc_server * server, struct evhttp_request * req) { const char * ours = get_current_session_id (server); const char * theirs = evhttp_find_header (req->input_headers, TR_RPC_SESSION_ID_HEADER); - const bool success = theirs && !strcmp (theirs, ours); + const bool success = theirs != NULL && strcmp (theirs, ours) == 0; return success; } @@ -638,7 +638,7 @@ handle_request (struct evhttp_request * req, void * arg) "

If you're still using ACLs, use a whitelist instead. See the transmission-daemon manpage for details.

"); } else if (server->isPasswordEnabled - && (!pass || !user || strcmp (server->username, user) + && (pass == NULL || user == NULL || strcmp (server->username, user) != 0 || !tr_ssha1_matches (server->password, pass))) { @@ -647,18 +647,18 @@ handle_request (struct evhttp_request * req, void * arg) "Basic realm=\"" MY_REALM "\""); send_simple_response (req, 401, "Unauthorized User"); } - else if (strncmp (req->uri, server->url, strlen (server->url))) + else if (strncmp (req->uri, server->url, strlen (server->url)) != 0) { char * location = tr_strdup_printf ("%sweb/", server->url); evhttp_add_header (req->output_headers, "Location", location); send_simple_response (req, HTTP_MOVEPERM, NULL); tr_free (location); } - else if (!strncmp (req->uri + strlen (server->url), "web/", 4)) + else if (strncmp (req->uri + strlen (server->url), "web/", 4) == 0) { handle_web_client (req, server); } - else if (!strcmp (req->uri + strlen (server->url), "upload")) + else if (strcmp (req->uri + strlen (server->url), "upload") == 0) { handle_upload (req, server); } @@ -683,7 +683,7 @@ handle_request (struct evhttp_request * req, void * arg) tr_free (tmp); } #endif - else if (!strncmp (req->uri + strlen (server->url), "rpc", 3)) + else if (strncmp (req->uri + strlen (server->url), "rpc", 3) == 0) { handle_rpc (req, server); } diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 46fd3192c..a576487d9 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -154,7 +154,7 @@ getTorrents (tr_session * session, } else if (tr_variantDictFindStr (args, TR_KEY_ids, &str, NULL)) { - if (!strcmp (str, "recently-active")) + if (strcmp (str, "recently-active") == 0) { tr_torrent * tor = NULL; const time_t now = tr_time (); @@ -935,7 +935,7 @@ torrentGet (tr_session * session, assert (idle_data == NULL); - if (tr_variantDictFindStr (args_in, TR_KEY_ids, &strVal, NULL) && !strcmp (strVal, "recently-active")) + if (tr_variantDictFindStr (args_in, TR_KEY_ids, &strVal, NULL) && strcmp (strVal, "recently-active") == 0) { int n = 0; tr_variant * d; @@ -1053,7 +1053,7 @@ findAnnounceUrl (const tr_tracker_info * t, int n, const char * url, int * pos) for (i=0; iaddr)); + *is_default_value = tr_strcmp0 (default_value, tr_address_to_string (&bindinfo->addr)) == 0; return bindinfo ? &bindinfo->addr : NULL; } @@ -991,7 +991,7 @@ tr_sessionGetDirFreeSpace (tr_session * session, const char * dir) { int64_t free_space; - if (!tr_strcmp0 (dir, tr_sessionGetDownloadDir (session))) + if (tr_strcmp0 (dir, tr_sessionGetDownloadDir (session)) == 0) free_space = tr_device_info_get_free_space (session->downloadDir); else free_space = tr_getDirFreeSpace (dir); @@ -2263,7 +2263,7 @@ tr_stringEndsWith (const char * str, const char * end) const size_t slen = strlen (str); const size_t elen = strlen (end); - return slen >= elen && !memcmp (&str[slen - elen], end, elen); + return slen >= elen && memcmp (&str[slen - elen], end, elen) == 0; } static void diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index 26fee485c..b1f1e6eff 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -264,7 +264,7 @@ tr_torrentSetMetadataPiece (tr_torrent * tor, int piece, const void * data, in /* we've got a complete set of metainfo... see if it passes the checksum test */ dbgmsg (tor, "metainfo piece %d was the last one", piece); tr_sha1 (sha1, m->metadata, m->metadata_size, NULL); - if ((checksumPassed = !memcmp (sha1, tor->info.hash, SHA_DIGEST_LENGTH))) + if ((checksumPassed = memcmp (sha1, tor->info.hash, SHA_DIGEST_LENGTH) == 0)) { /* checksum passed; now try to parse it as benc */ tr_variant infoDict; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index dbcaf87bd..e0e506731 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -112,7 +112,7 @@ tr_torrentFindFromHash (tr_session * session, const uint8_t * torrentHash) while ((tor = tr_torrentNext (session, tor))) if (*tor->info.hash == *torrentHash) - if (!memcmp (tor->info.hash, torrentHash, SHA_DIGEST_LENGTH)) + if (memcmp (tor->info.hash, torrentHash, SHA_DIGEST_LENGTH) == 0) return tor; return NULL; @@ -140,7 +140,7 @@ tr_torrentFindFromObfuscatedHash (tr_session * session, tr_torrent * tor = NULL; while ((tor = tr_torrentNext (session, tor))) - if (!memcmp (tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH)) + if (memcmp (tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH) == 0) return tor; return NULL; @@ -1080,7 +1080,7 @@ tr_torrentSetDownloadDir (tr_torrent * tor, const char * path) { assert (tr_isTorrent (tor)); - if (!path || !tor->downloadDir || strcmp (path, tor->downloadDir)) + if (path == NULL || tor->downloadDir == NULL || strcmp (path, tor->downloadDir) != 0) { tr_free (tor->downloadDir); tor->downloadDir = tr_strdup (path); @@ -2785,7 +2785,7 @@ tr_torrentSetAnnounceList (tr_torrent * tor, bool clear = true; for (i=0; clear && ierrorTracker)) + if (strcmp (trackers[i].announce, tor->errorTracker) == 0) clear = false; if (clear) @@ -2882,12 +2882,12 @@ isJunkFile (const char * base) static const int file_count = sizeof (files) / sizeof (files[0]); for (i=0; i */ - if (!memcmp (base, "._", 2)) + if (memcmp (base, "._", 2) == 0) return true; #endif @@ -3262,7 +3262,7 @@ tr_torrentFileCompleted (tr_torrent * tor, tr_file_index_t fileIndex) * it until now -- then rename it to match the one in the metadata */ if (tr_torrentFindFile2 (tor, fileIndex, &base, &sub, NULL)) { - if (strcmp (sub, f->name)) + if (strcmp (sub, f->name) != 0) { char * oldpath = tr_buildPath (base, sub, NULL); char * newpath = tr_buildPath (base, f->name, NULL); @@ -3648,8 +3648,8 @@ renameArgsAreValid (const char * oldpath, const char * newname) { return (oldpath && *oldpath) && (newname && *newname) - && (strcmp (newname, ".")) - && (strcmp (newname, "..")) + && (strcmp (newname, ".") != 0) + && (strcmp (newname, "..") != 0) && (strchr (newname, TR_PATH_DELIMITER) == NULL); } @@ -3668,7 +3668,7 @@ renameFindAffectedFiles (tr_torrent * tor, const char * oldpath, size_t * setme_ const char * name = tor->info.files[i].name; const size_t len = strlen (name); if ((len == oldpath_len || (len > oldpath_len && name[oldpath_len] == '/')) && - !memcmp (oldpath, name, oldpath_len)) + memcmp (oldpath, name, oldpath_len) == 0) indices[n++] = i; } @@ -3768,7 +3768,7 @@ renameTorrentFileString (tr_torrent * tor, tr_free (tmp); } - if (!strcmp (file->name, name)) + if (strcmp (file->name, name) == 0) { tr_free (name); } diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index a5c4d9f51..761409f55 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -149,7 +149,7 @@ findOption (const tr_option * opts, if ((matchlen < len) && (str[0] == '-') && (str[1] == '-') - && !strncmp (str+2, o->longName, len) + && strncmp (str+2, o->longName, len) == 0 && (str[len + 2] == '\0' || (o->has_arg && str[len + 2] == '='))) { matchlen = len; @@ -161,7 +161,7 @@ findOption (const tr_option * opts, if ((matchlen < len) && (str[0] == '-') - && !strncmp (str+1, o->shortName, len) + && strncmp (str+1, o->shortName, len) == 0 && (str[len + 1] == '\0' || o->has_arg)) { matchlen = len; @@ -202,7 +202,7 @@ tr_getopt (const char * usage, /* handle the builtin 'help' option */ for (i = 1; i < argc; ++i) { - if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) + if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0) { tr_getopt_usage (argv[0], usage, opts); exit (0); diff --git a/libtransmission/utils.c b/libtransmission/utils.c index bdb5407d9..4fc7a610b 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -188,7 +188,7 @@ tr_strip_positional_args (const char* str) } *out = '\0'; - return !in || strcmp (buf, in) ? buf : in; + return (in == NULL || strcmp (buf, in) != 0) ? buf : in; } /** @@ -403,7 +403,7 @@ tr_memmem (const char * haystack, size_t haystacklen, if (needlelen > haystacklen || !haystack || !needle) return NULL; for (i=0; i<=haystacklen-needlelen; ++i) - if (!memcmp (haystack+i, needle, needlelen)) + if (memcmp (haystack + i, needle, needlelen) == 0) return haystack+i; return NULL; #endif diff --git a/libtransmission/variant-test.c b/libtransmission/variant-test.c index 1a66b63a5..a69001b8d 100644 --- a/libtransmission/variant-test.c +++ b/libtransmission/variant-test.c @@ -113,7 +113,7 @@ testStr (void) err = tr_bencParseStr (buf, buf+n, &end, &str, &len); check_int_eq (0, err); check_int_eq (4, len); - check (!strncmp ((const char*)str, "boat", len)); + check (strncmp ((const char*)str, "boat", len) == 0); check (end == buf + 6); str = NULL; end = NULL; @@ -143,7 +143,7 @@ testStr (void) err = tr_bencParseStr (buf, buf+n, &end, &str, &len); check_int_eq (0, err); check_int_eq (3, len); - check (!strncmp ((const char*)str, "boa", len)); + check (strncmp ((const char*)str, "boa", len) == 0); check (end == buf + 5); str = NULL; end = NULL; diff --git a/libtransmission/variant.c b/libtransmission/variant.c index 2a7eb58bd..775c5f651 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -359,8 +359,8 @@ tr_variantGetBool (const tr_variant * v, bool * setme) *setme = v->val.i!=0; if (!success && tr_variantGetStr (v, &str, NULL)) - if ((success = (!strcmp (str,"true") || !strcmp (str,"false")))) - *setme = !strcmp (str,"true"); + if ((success = (strcmp (str,"true") == 0 || strcmp (str,"false") == 0))) + *setme = strcmp (str,"true") == 0; return success; } diff --git a/libtransmission/verify.c b/libtransmission/verify.c index f0882d7bc..fdbf9c810 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -116,7 +116,7 @@ verifyTorrent (tr_torrent * tor, bool * stopFlag) uint8_t hash[SHA_DIGEST_LENGTH]; tr_sha1_final (sha, hash); - hasPiece = !memcmp (hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH); + hasPiece = memcmp (hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH) == 0; if (hasPiece || hadPiece) { diff --git a/macosx/main.m b/macosx/main.m index 737a2eb42..8ea81cfac 100644 --- a/macosx/main.m +++ b/macosx/main.m @@ -26,7 +26,7 @@ int main( int argc, char ** argv ) { - if( argc > 1 && !strncmp( argv[1], "-v", 2 ) ) + if( argc > 1 && strncmp( argv[1], "-v", 2 ) == 0 ) { char * env; int debug = atoi( &argv[1][2] ); diff --git a/qt/OptionsDialog.cc b/qt/OptionsDialog.cc index e2d2e962c..e74adf66e 100644 --- a/qt/OptionsDialog.cc +++ b/qt/OptionsDialog.cc @@ -398,9 +398,9 @@ OptionsDialog::onTimeout () if (leftInPiece == 0) { const QByteArray result (myVerifyHash.result ()); - const bool matches = !memcmp (result.constData (), - myInfo.pieces[myVerifyPieceIndex].hash, - SHA_DIGEST_LENGTH); + const bool matches = memcmp (result.constData (), + myInfo.pieces[myVerifyPieceIndex].hash, + SHA_DIGEST_LENGTH) == 0; myVerifyFlags[myVerifyPieceIndex] = matches; myVerifyPiecePos = 0; ++myVerifyPieceIndex; diff --git a/qt/Session.cc b/qt/Session.cc index cbf4adda4..52d928a70 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -774,11 +774,11 @@ Session::updateInfo (tr_variant * d) const char * val; if (tr_variantGetStr (b, &val, NULL)) { - if (!qstrcmp (val , "required")) + if (qstrcmp (val , "required") == 0) myPrefs.set (i, 2); - else if (!qstrcmp (val , "preferred")) + else if (qstrcmp (val , "preferred") == 0) myPrefs.set (i, 1); - else if (!qstrcmp (val , "tolerated")) + else if (qstrcmp (val , "tolerated") == 0) myPrefs.set (i, 0); } continue; diff --git a/utils/edit.c b/utils/edit.c index fed13a897..5d0a36096 100644 --- a/utils/edit.c +++ b/utils/edit.c @@ -93,7 +93,7 @@ removeURL (tr_variant * metainfo, const char * url) tr_variant * announce_list; bool changed = false; - if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && !strcmp (str, url)) + if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && strcmp (str, url) == 0) { printf ("\tRemoved \"%s\" from \"announce\"\n", str); tr_variantDictRemove (metainfo, TR_KEY_announce); @@ -110,7 +110,7 @@ removeURL (tr_variant * metainfo, const char * url) int nodeIndex = 0; while ((node = tr_variantListChild (tier, nodeIndex))) { - if (tr_variantGetStr (node, &str, NULL) && !strcmp (str, url)) + if (tr_variantGetStr (node, &str, NULL) && strcmp (str, url) == 0) { printf ("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex+1)); tr_variantListRemove (tier, nodeIndex); @@ -233,7 +233,7 @@ announce_list_has_url (tr_variant * announce_list, const char * url) const char * str; int nodeCount = 0; while ((node = tr_variantListChild (tier, nodeCount++))) - if (tr_variantGetStr (node, &str, NULL) && !strcmp (str, url)) + if (tr_variantGetStr (node, &str, NULL) && strcmp (str, url) == 0) return true; } diff --git a/utils/show.c b/utils/show.c index 03d343291..4630716e9 100644 --- a/utils/show.c +++ b/utils/show.c @@ -256,7 +256,7 @@ doScrape (const tr_info * inf) while (tr_variantDictChild (files, i++, &key, &val)) { - if (!memcmp (inf->hash, tr_quark_get_string(key,NULL), SHA_DIGEST_LENGTH)) + if (memcmp (inf->hash, tr_quark_get_string (key, NULL), SHA_DIGEST_LENGTH) == 0) { int64_t seeders = -1; int64_t leechers = -1; -- 2.40.0