Couldn't find Transmission's web interface files!
" @@ -463,12 +463,12 @@ static void handle_web_client(struct evhttp_request* req, struct tr_rpc_server* subpath = tr_strdup(req->uri + strlen(server->url) + 4); - if ((pch = strchr(subpath, '?'))) + if ((pch = strchr(subpath, '?')) != NULL) { *pch = '\0'; } - if (strstr(subpath, "..")) + if (strstr(subpath, "..") != NULL) { send_simple_response(req, HTTP_NOTFOUND, "Tsk, tsk.
"); } @@ -532,7 +532,7 @@ static void handle_rpc(struct evhttp_request* req, struct tr_rpc_server* server) handle_rpc_from_json(req, server, (char const*)evbuffer_pullup(req->input_buffer, -1), evbuffer_get_length(req->input_buffer)); } - else if ((req->type == EVHTTP_REQ_GET) && ((q = strchr(req->uri, '?')))) + else if (req->type == EVHTTP_REQ_GET && (q = strchr(req->uri, '?')) != NULL) { struct rpc_response_data* data = tr_new0(struct rpc_response_data, 1); data->req = req; @@ -577,7 +577,7 @@ static void handle_request(struct evhttp_request* req, void* arg) { struct tr_rpc_server* server = arg; - if (req && req->evcon) + if (req != NULL && req->evcon != NULL) { char const* auth; char* user = NULL; @@ -587,7 +587,7 @@ static void handle_request(struct evhttp_request* req, void* arg) auth = evhttp_find_header(req->input_headers, "Authorization"); - if (auth && !evutil_ascii_strncasecmp(auth, "basic ", 6)) + if (auth != NULL && evutil_ascii_strncasecmp(auth, "basic ", 6) == 0) { size_t plen; char* p = tr_base64_decode_str(auth + 6, &plen); @@ -843,7 +843,7 @@ void tr_rpcSetUrl(tr_rpc_server* server, char const* url) char const* tr_rpcGetUrl(tr_rpc_server const* server) { - return server->url ? server->url : ""; + return server->url != NULL ? server->url : ""; } void tr_rpcSetWhitelist(tr_rpc_server* server, char const* whitelistStr) @@ -857,13 +857,13 @@ void tr_rpcSetWhitelist(tr_rpc_server* server, char const* whitelistStr) tr_free(tmp); /* clear out the old whitelist entries */ - while ((tmp = tr_list_pop_front(&server->whitelist))) + while ((tmp = tr_list_pop_front(&server->whitelist)) != NULL) { tr_free(tmp); } /* build the new whitelist entries */ - for (walk = whitelistStr; walk && *walk;) + for (walk = whitelistStr; walk != NULL && *walk != '\0';) { char const* delimiters = " ,;"; size_t const len = strcspn(walk, delimiters); @@ -891,7 +891,7 @@ void tr_rpcSetWhitelist(tr_rpc_server* server, char const* whitelistStr) char const* tr_rpcGetWhitelist(tr_rpc_server const* server) { - return server->whitelistStr ? server->whitelistStr : ""; + return server->whitelistStr != NULL ? server->whitelistStr : ""; } void tr_rpcSetWhitelistEnabled(tr_rpc_server* server, bool isEnabled) @@ -920,7 +920,7 @@ void tr_rpcSetUsername(tr_rpc_server* server, char const* username) char const* tr_rpcGetUsername(tr_rpc_server const* server) { - return server->username ? server->username : ""; + return server->username != NULL ? server->username : ""; } void tr_rpcSetPassword(tr_rpc_server* server, char const* password) @@ -941,7 +941,7 @@ void tr_rpcSetPassword(tr_rpc_server* server, char const* password) char const* tr_rpcGetPassword(tr_rpc_server const* server) { - return server->password ? server->password : ""; + return server->password != NULL ? server->password : ""; } void tr_rpcSetPasswordEnabled(tr_rpc_server* server, bool isEnabled) @@ -974,7 +974,7 @@ static void closeServer(void* vserver) stopServer(s); - while ((tmp = tr_list_pop_front(&s->whitelist))) + while ((tmp = tr_list_pop_front(&s->whitelist)) != NULL) { tr_free(tmp); } @@ -1072,7 +1072,7 @@ tr_rpc_server* tr_rpcInit(tr_session* session, tr_variant* settings) key = TR_KEY_rpc_whitelist; - if (!tr_variantDictFindStr(settings, key, &str, NULL) && str) + if (!tr_variantDictFindStr(settings, key, &str, NULL) && str != NULL) { missing_settings_key(key); } diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 5f30591fd..2cdcb6ba5 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -72,7 +72,7 @@ static tr_rpc_callback_status notify(tr_session* session, int type, tr_torrent* { tr_rpc_callback_status status = 0; - if (session->rpc_func) + if (session->rpc_func != NULL) { status = session->rpc_func(session, type, tor, session->rpc_func_user_data); } @@ -161,7 +161,7 @@ static tr_torrent** getTorrents(tr_session* session, tr_variant* args, int* setm tr_torrent* tor; torrents = tr_new0(tr_torrent*, 1); - if ((tor = tr_torrentFindFromId(session, id))) + if ((tor = tr_torrentFindFromId(session, id)) != NULL) { torrents[torrentCount++] = tor; } @@ -176,7 +176,7 @@ static tr_torrent** getTorrents(tr_session* session, tr_variant* args, int* setm int const n = tr_sessionCountTorrents(session); torrents = tr_new0(tr_torrent*, n); - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (tor->anyDate >= now - window) { @@ -189,7 +189,7 @@ static tr_torrent** getTorrents(tr_session* session, tr_variant* args, int* setm tr_torrent* tor; torrents = tr_new0(tr_torrent*, 1); - if ((tor = tr_torrentFindFromHashString(session, str))) + if ((tor = tr_torrentFindFromHashString(session, str)) != NULL) { torrents[torrentCount++] = tor; } @@ -373,7 +373,7 @@ static char const* torrentRemove(tr_session* session, tr_variant* args_in, tr_va tr_torrent* tor = torrents[i]; tr_rpc_callback_status const status = notify(session, type, tor); - if (!(status & TR_RPC_NOREMOVE)) + if ((status & TR_RPC_NOREMOVE) == 0) { tr_torrentRemove(tor, deleteFlag, NULL); } @@ -946,11 +946,11 @@ static char const* torrentGet(tr_session* session, tr_variant* args_in, tr_varia int const interval = RECENTLY_ACTIVE_SECONDS; tr_variant* removed_out = tr_variantDictAddList(args_out, TR_KEY_removed, 0); - while ((d = tr_variantListChild(&session->removedTorrents, n++))) + while ((d = tr_variantListChild(&session->removedTorrents, n++)) != NULL) { int64_t intVal; - if (tr_variantDictFindInt(d, TR_KEY_date, &intVal) && (intVal >= now - interval)) + if (tr_variantDictFindInt(d, TR_KEY_date, &intVal) && intVal >= now - interval) { tr_variantDictFindInt(d, TR_KEY_id, &intVal); tr_variantListAddInt(removed_out, intVal); @@ -987,7 +987,7 @@ static char const* setFilePriorities(tr_torrent* tor, int priority, tr_variant* char const* errmsg = NULL; tr_file_index_t* files = tr_new0(tr_file_index_t, tor->info.fileCount); - if (n) + if (n != 0) { for (i = 0; i < n; ++i) { @@ -1014,7 +1014,7 @@ static char const* setFilePriorities(tr_torrent* tor, int priority, tr_variant* } } - if (fileCount) + if (fileCount != 0) { tr_torrentSetFilePriorities(tor, files, fileCount, priority); } @@ -1032,7 +1032,7 @@ static char const* setFileDLs(tr_torrent* tor, bool do_download, tr_variant* lis char const* errmsg = NULL; tr_file_index_t* files = tr_new0(tr_file_index_t, tor->info.fileCount); - if (n) /* if argument list, process them */ + if (n != 0) /* if argument list, process them */ { for (i = 0; i < n; ++i) { @@ -1137,7 +1137,7 @@ static char const* addTrackerUrls(tr_torrent* tor, tr_variant* urls) /* and add the new ones */ i = 0; - while ((val = tr_variantListChild(urls, i++))) + while ((val = tr_variantListChild(urls, i++)) != NULL) { char const* announce = NULL; @@ -1181,7 +1181,7 @@ static char const* replaceTrackers(tr_torrent* tor, tr_variant* urls) /* make the substitutions... */ i = 0; - while (((pair[0] = tr_variantListChild(urls, i))) && ((pair[1] = tr_variantListChild(urls, i + 1)))) + while ((pair[0] = tr_variantListChild(urls, i)) != NULL && (pair[1] = tr_variantListChild(urls, i + 1)) != NULL) { size_t len; int64_t pos; @@ -1233,11 +1233,11 @@ static char const* removeTrackers(tr_torrent* tor, tr_variant* ids) /* remove the ones specified in the urls list */ i = 0; - while ((val = tr_variantListChild(ids, i++))) + while ((val = tr_variantListChild(ids, i++)) != NULL) { int64_t pos; - if (tr_variantGetInt(val, &pos) && (0 <= pos) && (pos < n)) + if (tr_variantGetInt(val, &pos) && 0 <= pos && pos < n) { tids[t++] = pos; } @@ -1246,7 +1246,7 @@ static char const* removeTrackers(tr_torrent* tor, tr_variant* ids) /* sort trackerIds and remove from largest to smallest so there is no need to recacluate array indicies */ qsort(tids, t, sizeof(int), compareInt); - while (t--) + while (t-- != 0) { /* check for duplicates */ if (tids[t] == dup) @@ -1304,12 +1304,12 @@ static char const* torrentSet(tr_session* session, tr_variant* args_in, tr_varia } } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_files_unwanted, &files)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_files_unwanted, &files)) { errmsg = setFileDLs(tor, false, files); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_files_wanted, &files)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_files_wanted, &files)) { errmsg = setFileDLs(tor, true, files); } @@ -1319,17 +1319,17 @@ static char const* torrentSet(tr_session* session, tr_variant* args_in, tr_varia tr_torrentSetPeerLimit(tor, tmp); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_priority_high, &files)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_priority_high, &files)) { errmsg = setFilePriorities(tor, TR_PRI_HIGH, files); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_priority_low, &files)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_priority_low, &files)) { errmsg = setFilePriorities(tor, TR_PRI_LOW, files); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_priority_normal, &files)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_priority_normal, &files)) { errmsg = setFilePriorities(tor, TR_PRI_NORMAL, files); } @@ -1384,17 +1384,17 @@ static char const* torrentSet(tr_session* session, tr_variant* args_in, tr_varia tr_torrentSetQueuePosition(tor, tmp); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_trackerAdd, &trackers)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_trackerAdd, &trackers)) { errmsg = addTrackerUrls(tor, trackers); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_trackerRemove, &trackers)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_trackerRemove, &trackers)) { errmsg = removeTrackers(tor, trackers); } - if (!errmsg && tr_variantDictFindList(args_in, TR_KEY_trackerReplace, &trackers)) + if (errmsg == NULL && tr_variantDictFindList(args_in, TR_KEY_trackerReplace, &trackers)) { errmsg = replaceTrackers(tor, trackers); } @@ -1513,7 +1513,7 @@ static void portTested(tr_session* session UNUSED, bool did_connect UNUSED, bool } else /* success */ { - bool const isOpen = response_byte_count && *(char*)response == '1'; + bool const isOpen = response_byte_count != 0 && *(char*)response == '1'; tr_variantDictAddBool(data->args_out, TR_KEY_port_is_open, isOpen); tr_snprintf(result, sizeof(result), "success"); } @@ -1597,7 +1597,7 @@ static void gotNewBlocklist(tr_session* session, bool did_connect UNUSED, bool d if (err != Z_OK) { - if ((err != Z_STREAM_END) && (err != Z_DATA_ERROR)) + if (err != Z_STREAM_END && err != Z_DATA_ERROR) { tr_snprintf(result, sizeof(result), _("Error uncompressing blocklist: %s (%d)"), zError(err), err); } @@ -1619,7 +1619,7 @@ static void gotNewBlocklist(tr_session* session, bool did_connect UNUSED, bool d tr_sys_file_close(fd, NULL); - if (*result) + if (*result != '\0') { tr_logAddError("%s", result); } @@ -1663,7 +1663,7 @@ static void addTorrentImpl(struct tr_rpc_idle_data* data, tr_ctor* ctor) tor = tr_torrentNew(ctor, &err, &duplicate_id); tr_ctorFree(ctor); - if (!err) + if (err == 0) { key = TR_KEY_torrent_added; result = NULL; @@ -1680,7 +1680,7 @@ static void addTorrentImpl(struct tr_rpc_idle_data* data, tr_ctor* ctor) result = "invalid or corrupt torrent file"; } - if (tor && key) + if (tor != NULL && key != 0) { tr_variant fields; tr_variantInitList(&fields, 3); @@ -1773,7 +1773,7 @@ static char const* torrentAdd(tr_session* session, tr_variant* args_in, tr_varia tr_variantDictFindStr(args_in, TR_KEY_filename, &filename, NULL); tr_variantDictFindStr(args_in, TR_KEY_metainfo, &metainfo_base64, NULL); - if (!filename && !metainfo_base64) + if (filename == NULL && metainfo_base64 == NULL) { return "no filename or metainfo specified"; } @@ -2166,7 +2166,7 @@ static char const* sessionStats(tr_session* session, tr_variant* args_in UNUSED, assert(idle_data == NULL); - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { ++total; @@ -2719,28 +2719,28 @@ void tr_rpc_request_exec_uri(tr_session* session, void const* request_uri, size_ pch = strchr(request, '?'); - if (!pch) + if (pch == NULL) { pch = request; } - while (pch) + while (pch != NULL) { char const* delim = strchr(pch, '='); char const* next = strchr(pch, '&'); - if (delim) + if (delim != NULL) { char* key = tr_strndup(pch, (size_t)(delim - pch)); bool isArg = strcmp(key, "method") != 0 && strcmp(key, "tag") != 0; tr_variant* parent = isArg ? args : ⊤ tr_rpc_parse_list_str(tr_variantDictAdd(parent, tr_quark_new(key, (size_t)(delim - pch))), delim + 1, - next ? (size_t)(next - (delim + 1)) : strlen(delim + 1)); + next != NULL ? (size_t)(next - (delim + 1)) : strlen(delim + 1)); tr_free(key); } - pch = next ? next + 1 : NULL; + pch = next != NULL ? next + 1 : NULL; } tr_rpc_request_exec_json(session, &top, callback, callback_user_data); diff --git a/libtransmission/session-test.c b/libtransmission/session-test.c index 42eb798d2..af9ffc616 100644 --- a/libtransmission/session-test.c +++ b/libtransmission/session-test.c @@ -39,7 +39,7 @@ static int testPeerId(void) val += strtoul(tmp, NULL, 36); } - check((val % 36) == 0); + check(val % 36 == 0); } return 0; diff --git a/libtransmission/session.c b/libtransmission/session.c index c2049cb66..2f8035e9f 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -109,7 +109,7 @@ void tr_peerIdInit(uint8_t* buf) buf[i] = pool[val]; } - val = total % base ? base - (total % base) : 0; + val = total % base != 0 ? base - (total % base) : 0; buf[19] = pool[val]; buf[20] = '\0'; } @@ -120,14 +120,14 @@ void tr_peerIdInit(uint8_t* buf) tr_encryption_mode tr_sessionGetEncryption(tr_session* session) { - assert(session); + assert(session != NULL); return session->encryptionMode; } void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode) { - assert(session); + assert(session != NULL); assert(mode == TR_ENCRYPTION_PREFERRED || mode == TR_ENCRYPTION_REQUIRED || mode == TR_CLEAR_PREFERRED); session->encryptionMode = mode; @@ -146,7 +146,7 @@ struct tr_bindinfo static void close_bindinfo(struct tr_bindinfo* b) { - if ((b != NULL) && (b->socket != TR_BAD_SOCKET)) + if (b != NULL && b->socket != TR_BAD_SOCKET) { event_free(b->ev); b->ev = NULL; @@ -239,12 +239,12 @@ tr_address const* tr_sessionGetPublicAddress(tr_session const* session, int tr_a break; } - if (is_default_value && bindinfo) + if (is_default_value != NULL && bindinfo != NULL) { *is_default_value = tr_strcmp0(default_value, tr_address_to_string(&bindinfo->addr)) == 0; } - return bindinfo ? &bindinfo->addr : NULL; + return bindinfo != NULL ? &bindinfo->addr : NULL; } /*** @@ -262,44 +262,44 @@ static int parse_tos(char const* str) char* p; int value; - if (!evutil_ascii_strcasecmp(str, "")) + if (evutil_ascii_strcasecmp(str, "") == 0) { return 0; } - if (!evutil_ascii_strcasecmp(str, "default")) + if (evutil_ascii_strcasecmp(str, "default") == 0) { return 0; } - if (!evutil_ascii_strcasecmp(str, "lowcost")) + if (evutil_ascii_strcasecmp(str, "lowcost") == 0) { return 0x10; } - if (!evutil_ascii_strcasecmp(str, "mincost")) + if (evutil_ascii_strcasecmp(str, "mincost") == 0) { return 0x10; } - if (!evutil_ascii_strcasecmp(str, "throughput")) + if (evutil_ascii_strcasecmp(str, "throughput") == 0) { return 0x08; } - if (!evutil_ascii_strcasecmp(str, "reliability")) + if (evutil_ascii_strcasecmp(str, "reliability") == 0) { return 0x04; } - if (!evutil_ascii_strcasecmp(str, "lowdelay")) + if (evutil_ascii_strcasecmp(str, "lowdelay") == 0) { return 0x02; } value = strtol(str, &p, 0); - if (!p || (p == str)) + if (p == NULL || p == str) { return 0; } @@ -494,7 +494,7 @@ bool tr_sessionLoadSettings(tr_variant* dict, char const* configDir, char const* tr_variantFree(&oldDict); /* if caller didn't specify a config dir, use the default */ - if (!configDir || !*configDir) + if (configDir == NULL || *configDir == '\0') { configDir = tr_getDefaultConfigDir(appName); } @@ -573,12 +573,12 @@ static void onSaveTimer(evutil_socket_t foo UNUSED, short bar UNUSED, void* vses tr_torrent* tor = NULL; tr_session* session = vsession; - if (tr_cacheFlushDone(session->cache)) + if (tr_cacheFlushDone(session->cache) != 0) { tr_logAddError("Error while flushing completed pieces from cache"); } - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { tr_torrentSave(tor); } @@ -679,7 +679,7 @@ static void onNowTimer(evutil_socket_t foo UNUSED, short bar UNUSED, void* vsess turtleCheckClock(session, &session->turtle); } - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (tor->isRunning) { @@ -974,7 +974,7 @@ static void sessionSetImpl(void* vdata) tr_variantDictFindStr(settings, TR_KEY_bind_address_ipv4, &str, NULL); - if (!tr_address_from_string(&b.addr, str) || (b.addr.type != TR_AF_INET)) + if (!tr_address_from_string(&b.addr, str) || b.addr.type != TR_AF_INET) { b.addr = tr_inaddr_any; } @@ -984,7 +984,7 @@ static void sessionSetImpl(void* vdata) tr_variantDictFindStr(settings, TR_KEY_bind_address_ipv6, &str, NULL); - if (!tr_address_from_string(&b.addr, str) || (b.addr.type != TR_AF_INET6)) + if (!tr_address_from_string(&b.addr, str) || b.addr.type != TR_AF_INET6) { b.addr = tr_in6addr_any; } @@ -1178,7 +1178,7 @@ char const* tr_sessionGetDownloadDir(tr_session const* session) assert(tr_isSession(session)); - if ((session != NULL) && (session->downloadDir != NULL)) + if (session != NULL && session->downloadDir != NULL) { dir = session->downloadDir->path; } @@ -1296,7 +1296,7 @@ static void peerPortChanged(void* session) open_incoming_peer_port(session); tr_sharedPortChanged(session); - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { tr_torrentChangeMyPort(tor); } @@ -1312,7 +1312,7 @@ static void setPeerPort(tr_session* session, tr_port port) void tr_sessionSetPeerPort(tr_session* session, tr_port port) { - if (tr_isSession(session) && (session->private_peer_port != port)) + if (tr_isSession(session) && session->private_peer_port != port) { setPeerPort(session, port); } @@ -1458,7 +1458,7 @@ static void updateBandwidth(tr_session* session, tr_direction dir) { unsigned int limit_Bps = 0; bool const isLimited = tr_sessionGetActiveSpeedLimit_Bps(session, dir, &limit_Bps); - bool const zeroCase = isLimited && !limit_Bps; + bool const zeroCase = isLimited && limit_Bps == 0; tr_bandwidthSetLimited(&session->bandwidth, dir, isLimited && !zeroCase); @@ -1481,7 +1481,7 @@ static void turtleUpdateTable(struct tr_turtle_info* t) for (day = 0; day < 7; ++day) { - if (t->days & (1 << day)) + if ((t->days & (1 << day)) != 0) { int i; time_t const begin = t->beginMinute; @@ -1567,11 +1567,11 @@ static void turtleCheckClock(tr_session* s, struct tr_turtle_info* t) enabled = getInTurtleTime(t); newAutoTurtleState = autoSwitchState(enabled); - alreadySwitched = (t->autoTurtleState == newAutoTurtleState); + alreadySwitched = t->autoTurtleState == newAutoTurtleState; if (!alreadySwitched) { - tr_logAddInfo("Time to turn %s turtle mode!", (enabled ? "on" : "off")); + tr_logAddInfo("Time to turn %s turtle mode!", enabled ? "on" : "off"); t->autoTurtleState = newAutoTurtleState; useAltSpeed(s, t, enabled, false); } @@ -1721,7 +1721,7 @@ bool tr_sessionUsesAltSpeedTime(tr_session const* s) void tr_sessionSetAltSpeedBegin(tr_session* s, int minute) { assert(tr_isSession(s)); - assert(0 <= minute && minute < (60 * 24)); + assert(0 <= minute && minute < 60 * 24); if (s->turtle.beginMinute != minute) { @@ -1740,7 +1740,7 @@ int tr_sessionGetAltSpeedBegin(tr_session const* s) void tr_sessionSetAltSpeedEnd(tr_session* s, int minute) { assert(tr_isSession(s)); - assert(0 <= minute && minute < (60 * 24)); + assert(0 <= minute && minute < 60 * 24); if (s->turtle.endMinute != minute) { @@ -2067,7 +2067,8 @@ void tr_sessionClose(tr_session* session) * so we need to keep the transmission thread alive * for a bit while they tell the router & tracker * that we're closing now */ - while ((session->shared || session->web || session->announcer || session->announcer_udp) && !deadlineReached(deadline)) + while ((session->shared != NULL || session->web != NULL || session->announcer != NULL || session->announcer_udp != NULL) && + !deadlineReached(deadline)) { dbgmsg("waiting on port unmap (%p) or announcer (%p)... now %zu deadline %zu", (void*)session->shared, (void*)session->announcer, (size_t)time(NULL), (size_t)deadline); @@ -2106,7 +2107,7 @@ void tr_sessionClose(tr_session* session) tr_session_id_free(session->session_id); tr_lockFree(session->lock); - if (session->metainfoLookup) + if (session->metainfoLookup != NULL) { tr_variantFree(session->metainfoLookup); tr_free(session->metainfoLookup); @@ -2160,7 +2161,7 @@ static void sessionLoadTorrents(void* vdata) char* path = tr_buildPath(dirname, name, NULL); tr_ctorSetMetainfoFromFile(data->ctor, path); - if ((tor = tr_torrentNew(data->ctor, NULL, NULL))) + if ((tor = tr_torrentNew(data->ctor, NULL, NULL)) != NULL) { tr_list_prepend(&list, tor); ++n; @@ -2184,12 +2185,12 @@ static void sessionLoadTorrents(void* vdata) tr_list_free(&list, NULL); - if (n) + if (n != 0) { tr_logAddInfo(_("Loaded %d torrents"), n); } - if (data->setmeCount) + if (data->setmeCount != NULL) { *data->setmeCount = n; } @@ -2554,7 +2555,7 @@ int tr_blocklistGetRuleCount(tr_session const* session) assert(tr_isSession(session)); - for (l = session->blocklists; l; l = l->next) + for (l = session->blocklists; l != NULL; l = l->next) { n += tr_blocklistFileGetRuleCount(l->data); } @@ -2599,7 +2600,7 @@ int tr_blocklistSetContent(tr_session* session, char const* contentFilename) char const* defaultName = DEFAULT_BLOCKLIST_FILENAME; tr_sessionLock(session); - for (b = NULL, l = session->blocklists; !b && l; l = l->next) + for (b = NULL, l = session->blocklists; b == NULL && l != NULL; l = l->next) { if (tr_stringEndsWith(tr_blocklistFileGetFilename(l->data), defaultName)) { @@ -2607,7 +2608,7 @@ int tr_blocklistSetContent(tr_session* session, char const* contentFilename) } } - if (!b) + if (b == NULL) { char* path = tr_buildPath(session->configDir, "blocklists", defaultName, NULL); b = tr_blocklistFileNew(path, session->isBlocklistEnabled); @@ -2626,7 +2627,7 @@ bool tr_sessionIsAddressBlocked(tr_session const* session, tr_address const* add assert(tr_isSession(session)); - for (l = session->blocklists; l; l = l->next) + for (l = session->blocklists; l != NULL; l = l->next) { if (tr_blocklistFileHasAddress(l->data, addr)) { @@ -2685,7 +2686,7 @@ static void metainfoLookupInit(tr_session* session) char* path = tr_buildPath(dirname, name, NULL); tr_ctorSetMetainfoFromFile(ctor, path); - if (!tr_torrentParse(ctor, &inf)) + if (tr_torrentParse(ctor, &inf) == TR_PARSE_OK) { ++n; tr_variantDictAddStr(lookup, tr_quark_new(inf.hashString, TR_BAD_SIZE), path); @@ -2708,7 +2709,7 @@ char const* tr_sessionFindTorrentFile(tr_session const* session, char const* has { char const* filename = NULL; - if (!session->metainfoLookup) + if (session->metainfoLookup == NULL) { metainfoLookupInit((tr_session*)session); } @@ -2724,7 +2725,7 @@ void tr_sessionSetTorrentFile(tr_session* session, char const* hashString, char * and tr_sessionSetTorrentFile() is just to tell us there's a new file * in that same directory, we don't need to do anything here if the * lookup table hasn't been built yet */ - if (session->metainfoLookup) + if (session->metainfoLookup != NULL) { tr_variantDictAddStr(session->metainfoLookup, tr_quark_new(hashString, TR_BAD_SIZE), filename); } @@ -3009,7 +3010,7 @@ void tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction direction i = 0; tor = NULL; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (!tr_torrentIsQueued(tor)) { @@ -3061,7 +3062,7 @@ int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir) tor = NULL; active_count = 0; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (!tr_torrentIsStalled(tor)) { diff --git a/libtransmission/session.h b/libtransmission/session.h index 9dd8bf45d..f73d3af30 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -266,22 +266,22 @@ enum static inline bool tr_isSession(tr_session const* session) { - return (session != NULL) && (session->magicNumber == SESSION_MAGIC_NUMBER); + return session != NULL && session->magicNumber == SESSION_MAGIC_NUMBER; } static inline bool tr_isPreallocationMode(tr_preallocation_mode m) { - return (m == TR_PREALLOCATE_NONE) || (m == TR_PREALLOCATE_SPARSE) || (m == TR_PREALLOCATE_FULL); + return m == TR_PREALLOCATE_NONE || m == TR_PREALLOCATE_SPARSE || m == TR_PREALLOCATE_FULL; } static inline bool tr_isEncryptionMode(tr_encryption_mode m) { - return (m == TR_CLEAR_PREFERRED) || (m == TR_ENCRYPTION_PREFERRED) || (m == TR_ENCRYPTION_REQUIRED); + return m == TR_CLEAR_PREFERRED || m == TR_ENCRYPTION_PREFERRED || m == TR_ENCRYPTION_REQUIRED; } static inline bool tr_isPriority(tr_priority_t p) { - return (p == TR_PRI_LOW) || (p == TR_PRI_NORMAL) || (p == TR_PRI_HIGH); + return p == TR_PRI_LOW || p == TR_PRI_NORMAL || p == TR_PRI_HIGH; } /*** diff --git a/libtransmission/stats.c b/libtransmission/stats.c index 3ebc02259..c3ebae903 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -132,7 +132,7 @@ void tr_statsSaveDirty(tr_session* session) { struct tr_stats_handle* h = getStats(session); - if ((h != NULL) && h->isDirty) + if (h != NULL && h->isDirty) { tr_session_stats cumulative = STATS_INIT; tr_sessionGetCumulativeStats(session, &cumulative); @@ -172,7 +172,7 @@ void tr_sessionGetStats(tr_session const* session, tr_session_stats* setme) { struct tr_stats_handle const* stats = getStats(session); - if (stats) + if (stats != NULL) { *setme = stats->single; setme->secondsActive = tr_time() - stats->startTime; @@ -185,7 +185,7 @@ void tr_sessionGetCumulativeStats(tr_session const* session, tr_session_stats* s struct tr_stats_handle const* stats = getStats(session); tr_session_stats current = STATS_INIT; - if (stats) + if (stats != NULL) { tr_sessionGetStats(session, ¤t); addStats(setme, &stats->old, ¤t); @@ -216,7 +216,7 @@ void tr_statsAddUploaded(tr_session* session, uint32_t bytes) { struct tr_stats_handle* s; - if ((s = getStats(session))) + if ((s = getStats(session)) != NULL) { s->single.uploadedBytes += bytes; s->isDirty = true; @@ -227,7 +227,7 @@ void tr_statsAddDownloaded(tr_session* session, uint32_t bytes) { struct tr_stats_handle* s; - if ((s = getStats(session))) + if ((s = getStats(session)) != NULL) { s->single.downloadedBytes += bytes; s->isDirty = true; @@ -238,7 +238,7 @@ void tr_statsFileCreated(tr_session* session) { struct tr_stats_handle* s; - if ((s = getStats(session))) + if ((s = getStats(session)) != NULL) { s->single.filesAdded++; } diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index f968124b3..0cb3e8a5b 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -129,7 +129,7 @@ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename) metainfo = tr_loadFile(filename, &len, NULL); - if (metainfo && len) + if (metainfo != NULL && len != 0) { err = tr_ctorSetMetainfo(ctor, metainfo, len); } @@ -158,7 +158,7 @@ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename) } } - if (!name || !*name) + if (name == NULL || *name == '\0') { char* base = tr_sys_path_basename(filename, NULL); @@ -182,7 +182,7 @@ int tr_ctorSetMetainfoFromHash(tr_ctor* ctor, char const* hashString) filename = tr_sessionFindTorrentFile(ctor->session, hashString); - if (!filename) + if (filename == NULL) { err = EINVAL; } @@ -258,12 +258,12 @@ void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* files, tr_file_ void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor) { - if (ctor->notWantSize) + if (ctor->notWantSize != 0) { tr_torrentInitFileDLs(tor, ctor->notWant, ctor->notWantSize, false); } - if (ctor->wantSize) + if (ctor->wantSize != 0) { tr_torrentInitFileDLs(tor, ctor->want, ctor->wantSize, true); } @@ -289,7 +289,7 @@ bool tr_ctorGetDeleteSource(tr_ctor const* ctor, bool* setme) { ret = false; } - else if (setme) + else if (setme != NULL) { *setme = ctor->doDelete; } @@ -318,7 +318,7 @@ void tr_ctorSetPaused(tr_ctor* ctor, tr_ctorMode mode, bool isPaused) struct optional_args* args; assert(ctor != NULL); - assert((mode == TR_FALLBACK) || (mode == TR_FORCE)); + assert(mode == TR_FALLBACK || mode == TR_FORCE); assert(tr_isBool(isPaused)); args = &ctor->optionalArgs[mode]; @@ -331,7 +331,7 @@ void tr_ctorSetPeerLimit(tr_ctor* ctor, tr_ctorMode mode, uint16_t peerLimit) struct optional_args* args; assert(ctor != NULL); - assert((mode == TR_FALLBACK) || (mode == TR_FORCE)); + assert(mode == TR_FALLBACK || mode == TR_FORCE); args = &ctor->optionalArgs[mode]; args->isSet_connected = true; @@ -343,14 +343,14 @@ void tr_ctorSetDownloadDir(tr_ctor* ctor, tr_ctorMode mode, char const* director struct optional_args* args; assert(ctor != NULL); - assert((mode == TR_FALLBACK) || (mode == TR_FORCE)); + assert(mode == TR_FALLBACK || mode == TR_FORCE); args = &ctor->optionalArgs[mode]; tr_free(args->downloadDir); args->downloadDir = NULL; args->isSet_downloadDir = false; - if (directory && *directory) + if (directory != NULL && *directory != '\0') { args->isSet_downloadDir = true; args->downloadDir = tr_strdup(directory); @@ -372,7 +372,7 @@ bool tr_ctorGetPeerLimit(tr_ctor const* ctor, tr_ctorMode mode, uint16_t* setmeC { ret = false; } - else if (setmeCount) + else if (setmeCount != NULL) { *setmeCount = args->peerLimit; } @@ -389,7 +389,7 @@ bool tr_ctorGetPaused(tr_ctor const* ctor, tr_ctorMode mode, bool* setmeIsPaused { ret = false; } - else if (setmeIsPaused) + else if (setmeIsPaused != NULL) { *setmeIsPaused = args->isPaused; } @@ -406,7 +406,7 @@ bool tr_ctorGetDownloadDir(tr_ctor const* ctor, tr_ctorMode mode, char const** s { ret = false; } - else if (setmeDownloadDir) + else if (setmeDownloadDir != NULL) { *setmeDownloadDir = args->downloadDir; } @@ -438,7 +438,7 @@ bool tr_ctorGetMetainfo(tr_ctor const* ctor, tr_variant const** setme) { ret = false; } - else if (setme) + else if (setme != NULL) { *setme = &ctor->metainfo; } @@ -457,7 +457,7 @@ tr_session* tr_ctorGetSession(tr_ctor const* ctor) static bool isPriority(int i) { - return (i == TR_PRI_LOW) || (i == TR_PRI_NORMAL) || (i == TR_PRI_HIGH); + return i == TR_PRI_LOW || i == TR_PRI_NORMAL || i == TR_PRI_HIGH; } void tr_ctorSetBandwidthPriority(tr_ctor* ctor, tr_priority_t priority) diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index c1bacbf1e..87e991f06 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -125,11 +125,11 @@ static size_t findInfoDictOffset(tr_torrent const* tor) size_t offset = 0; /* load the file, and find the info dict's offset inside the file */ - if ((fileContents = tr_loadFile(tor->info.torrent, &fileLen, NULL))) + if ((fileContents = tr_loadFile(tor->info.torrent, &fileLen, NULL)) != NULL) { tr_variant top; - if (!tr_variantFromBenc(&top, fileContents, fileLen)) + if (tr_variantFromBenc(&top, fileContents, fileLen) == 0) { tr_variant* infoDict; @@ -290,7 +290,7 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in int const err = tr_variantFromBenc(&infoDict, m->metadata, m->metadata_size); dbgmsg(tor, "err is %d", err); - if ((metainfoParsed = !err)) + if ((metainfoParsed = err == 0)) { /* yay we have bencoded metainfo... merge it into our .torrent file */ tr_variant newMetainfo; @@ -375,7 +375,7 @@ bool tr_torrentGetNextMetadataRequest(tr_torrent* tor, time_t now, int* setme_pi m = tor->incompleteMetadata; - if ((m != NULL) && (m->piecesNeededCount > 0) && (m->piecesNeeded[0].requestedAt + MIN_REPEAT_INTERVAL_SECS < now)) + if (m != NULL && m->piecesNeededCount > 0 && m->piecesNeeded[0].requestedAt + MIN_REPEAT_INTERVAL_SECS < now) { int i; int const piece = m->piecesNeeded[0].piece; @@ -406,7 +406,7 @@ double tr_torrentGetMetadataPercent(tr_torrent const* tor) { struct tr_incomplete_metadata const* m = tor->incompleteMetadata; - if (!m || !m->pieceCount) + if (m == NULL || m->pieceCount == 0) { ret = 0.0; } @@ -430,7 +430,7 @@ char* tr_torrentInfoGetMagnetLink(tr_info const* inf) name = inf->name; - if (name && *name) + if (name != NULL && *name != '\0') { evbuffer_add_printf(s, "%s", "&dn="); tr_http_escape(s, name, TR_BAD_SIZE, true); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 33c5de239..ade2c8c41 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -72,19 +72,19 @@ char const* tr_torrentName(tr_torrent const* tor) { - return tor ? tor->info.name : ""; + return tor != NULL ? tor->info.name : ""; } int tr_torrentId(tr_torrent const* tor) { - return tor ? tor->uniqueId : -1; + return tor != NULL ? tor->uniqueId : -1; } tr_torrent* tr_torrentFindFromId(tr_session* session, int id) { tr_torrent* tor = NULL; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (tor->uniqueId == id) { @@ -99,7 +99,7 @@ tr_torrent* tr_torrentFindFromHashString(tr_session* session, char const* str) { tr_torrent* tor = NULL; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (!evutil_ascii_strcasecmp(str, tor->info.hashString)) { @@ -114,7 +114,7 @@ tr_torrent* tr_torrentFindFromHash(tr_session* session, uint8_t const* torrentHa { tr_torrent* tor = NULL; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (*tor->info.hash == *torrentHash) { @@ -133,7 +133,7 @@ tr_torrent* tr_torrentFindFromMagnetLink(tr_session* session, char const* magnet tr_magnet_info* info; tr_torrent* tor = NULL; - if ((info = tr_magnetParse(magnet))) + if ((info = tr_magnetParse(magnet)) != NULL) { tor = tr_torrentFindFromHash(session, info->hash); tr_magnetFree(info); @@ -146,7 +146,7 @@ tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, uint8_t const* { tr_torrent* tor = NULL; - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (memcmp(tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH) == 0) { @@ -201,7 +201,7 @@ static int peerIdTTL(tr_torrent const* tor) { int ttl; - if (!tor->peer_id_creation_time) + if (tor->peer_id_creation_time == 0) { ttl = 0; } @@ -217,7 +217,7 @@ unsigned char const* tr_torrentGetPeerId(tr_torrent* tor) { bool needs_new_peer_id = false; - if (!*tor->peer_id) + if (*tor->peer_id == '\0') { needs_new_peer_id = true; } @@ -371,7 +371,7 @@ bool tr_torrentGetSeedRatio(tr_torrent const* tor, double* ratio) case TR_RATIOLIMIT_SINGLE: isLimited = true; - if (ratio) + if (ratio != NULL) { *ratio = tr_torrentGetRatioLimit(tor); } @@ -381,7 +381,7 @@ bool tr_torrentGetSeedRatio(tr_torrent const* tor, double* ratio) case TR_RATIOLIMIT_GLOBAL: isLimited = tr_sessionIsRatioLimited(tor->session); - if (isLimited && ratio) + if (isLimited && ratio != NULL) { *ratio = tr_sessionGetRatioLimit(tor->session); } @@ -412,12 +412,12 @@ static bool tr_torrentGetSeedRatioBytes(tr_torrent const* tor, uint64_t* setmeLe uint64_t const baseline = d ? d : tr_cpSizeWhenDone(&tor->completion); uint64_t const goal = baseline * seedRatio; - if (setmeLeft) + if (setmeLeft != NULL) { *setmeLeft = goal > u ? goal - u : 0; } - if (setmeGoal) + if (setmeGoal != NULL) { *setmeGoal = goal; } @@ -496,7 +496,7 @@ bool tr_torrentGetSeedIdle(tr_torrent const* tor, uint16_t* idleMinutes) case TR_IDLELIMIT_GLOBAL: isLimited = tr_sessionIsIdleLimited(tor->session); - if (isLimited && idleMinutes) + if (isLimited && idleMinutes != NULL) { *idleMinutes = tr_sessionGetIdleLimit(tor->session); } @@ -652,7 +652,7 @@ static tr_piece_index_t getBytePiece(tr_info const* info, uint64_t byteOffset) { tr_piece_index_t piece; - assert(info); + assert(info != NULL); assert(info->pieceSize != 0); piece = byteOffset / info->pieceSize; @@ -683,7 +683,7 @@ static void initFilePieces(tr_info* info, tr_file_index_t fileIndex) static bool pieceHasFile(tr_piece_index_t piece, tr_file const* file) { - return (file->firstPiece <= piece) && (piece <= file->lastPiece); + return file->firstPiece <= piece && piece <= file->lastPiece; } static tr_priority_t calculatePiecePriority(tr_torrent const* tor, tr_piece_index_t piece, int fileHint) @@ -820,7 +820,7 @@ uint32_t tr_getBlockSize(uint32_t pieceSize) b /= 2u; } - if (!b || (pieceSize % b)) /* not cleanly divisible */ + if (b == 0 || pieceSize % b != 0) /* not cleanly divisible */ { return 0; } @@ -837,34 +837,34 @@ static void torrentInitFromInfo(tr_torrent* tor) tor->blockSize = tr_getBlockSize(info->pieceSize); - if (info->pieceSize) + if (info->pieceSize != 0) { tor->lastPieceSize = (uint32_t)(info->totalSize % info->pieceSize); } - if (!tor->lastPieceSize) + if (tor->lastPieceSize == 0) { tor->lastPieceSize = info->pieceSize; } - if (tor->blockSize) + if (tor->blockSize != 0) { tor->lastBlockSize = info->totalSize % tor->blockSize; } - if (!tor->lastBlockSize) + if (tor->lastBlockSize == 0) { tor->lastBlockSize = tor->blockSize; } - tor->blockCount = tor->blockSize ? (info->totalSize + tor->blockSize - 1) / tor->blockSize : 0; - tor->blockCountInPiece = tor->blockSize ? info->pieceSize / tor->blockSize : 0; - tor->blockCountInLastPiece = tor->blockSize ? (tor->lastPieceSize + tor->blockSize - 1) / tor->blockSize : 0; + tor->blockCount = tor->blockSize != 0 ? (info->totalSize + tor->blockSize - 1) / tor->blockSize : 0; + tor->blockCountInPiece = tor->blockSize != 0 ? info->pieceSize / tor->blockSize : 0; + tor->blockCountInLastPiece = tor->blockSize != 0 ? (tor->lastPieceSize + tor->blockSize - 1) / tor->blockSize : 0; /* check our work */ if (tor->blockSize != 0) { - assert((info->pieceSize % tor->blockSize) == 0); + assert(info->pieceSize % tor->blockSize == 0); } t = info->pieceCount - 1; @@ -915,7 +915,7 @@ static bool hasAnyLocalData(tr_torrent const* tor) static bool setLocalErrorIfFilesDisappeared(tr_torrent* tor) { - bool const disappeared = (tr_torrentHaveTotal(tor) > 0) && !hasAnyLocalData(tor); + bool const disappeared = tr_torrentHaveTotal(tor) > 0 && !hasAnyLocalData(tor); if (disappeared) { @@ -971,8 +971,8 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) tr_peerMgrAddTorrent(session->peerMgr, tor); - assert(!tor->downloadedCur); - assert(!tor->uploadedCur); + assert(tor->downloadedCur == 0); + assert(tor->uploadedCur == 0); tr_torrentSetAddedDate(tor, tr_time()); /* this is a default value to be overwritten by the resume file */ @@ -989,7 +989,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) doStart = tor->isRunning; tor->isRunning = false; - if (!(loaded & TR_FR_SPEEDLIMIT)) + if ((loaded & TR_FR_SPEEDLIMIT) == 0) { tr_torrentUseSpeedLimit(tor, TR_UP, false); tr_torrentSetSpeedLimit_Bps(tor, TR_UP, tr_sessionGetSpeedLimit_Bps(tor->session, TR_UP)); @@ -998,13 +998,13 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) tr_torrentUseSessionLimits(tor, true); } - if (!(loaded & TR_FR_RATIOLIMIT)) + if ((loaded & TR_FR_RATIOLIMIT) == 0) { tr_torrentSetRatioMode(tor, TR_RATIOLIMIT_GLOBAL); tr_torrentSetRatioLimit(tor, tr_sessionGetRatioLimit(tor->session)); } - if (!(loaded & TR_FR_IDLELIMIT)) + if ((loaded & TR_FR_IDLELIMIT) == 0) { tr_torrentSetIdleMode(tor, TR_IDLELIMIT_GLOBAL); tr_torrentSetIdleLimit(tor, tr_sessionGetIdleLimit(tor->session)); @@ -1042,7 +1042,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) char const* path = tor->info.torrent; int const err = tr_variantToFile(val, TR_VARIANT_FMT_BENC, path); - if (err) + if (err != 0) { tr_torrentSetLocalError(tor, "Unable to save torrent file: %s", tr_strerror(err)); } @@ -1102,7 +1102,7 @@ static tr_parse_result torrentParseImpl(tr_ctor const* ctor, tr_info* setmeInfo, result = TR_PARSE_ERR; } - if (didParse && session && (result == TR_PARSE_OK)) + if (didParse && session != NULL && result == TR_PARSE_OK) { tr_torrent const* const tor = tr_torrentFindFromHash(session, setmeInfo->hash); @@ -1239,7 +1239,7 @@ void tr_torrentManualUpdate(tr_torrent* tor) bool tr_torrentCanManualUpdate(tr_torrent const* tor) { - return (tr_isTorrent(tor)) && (tor->isRunning) && (tr_announcerCanManualAnnounce(tor)); + return tr_isTorrent(tor) && tor->isRunning && tr_announcerCanManualAnnounce(tor); } tr_info const* tr_torrentInfo(tr_torrent const* tor) @@ -1251,7 +1251,7 @@ tr_stat const* tr_torrentStatCached(tr_torrent* tor) { time_t const now = tr_time(); - return tr_isTorrent(tor) && (now == tor->lastStatTime) ? &tor->stats : tr_torrentStat(tor); + return (tr_isTorrent(tor) && now == tor->lastStatTime) ? &tor->stats : tr_torrentStat(tor); } void tr_torrentSetVerifyState(tr_torrent* tor, tr_verify_state state) @@ -1316,7 +1316,7 @@ static time_t torrentGetIdleSecs(tr_torrent const* tor) bool tr_torrentIsStalled(tr_torrent const* tor) { return tr_sessionGetQueueStalledEnabled(tor->session) && - (torrentGetIdleSecs(tor) > (tr_sessionGetQueueStalledMinutes(tor->session) * 60)); + torrentGetIdleSecs(tor) > tr_sessionGetQueueStalledMinutes(tor->session) * 60; } static double getVerifyProgress(tr_torrent const* tor) @@ -1330,7 +1330,7 @@ static double getVerifyProgress(tr_torrent const* tor) for (i = 0, n = tor->info.pieceCount; i != n; ++i) { - if (tor->info.pieces[i].timeChecked) + if (tor->info.pieces[i].timeChecked != 0) { ++checked; } @@ -1427,15 +1427,15 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) * so, etaXLSpeed is a smoothed-out version of the piece speed * to dampen the effect of fluctuations */ case TR_STATUS_DOWNLOAD: - if ((tor->etaDLSpeedCalculatedAt + 800) < now) + if (tor->etaDLSpeedCalculatedAt + 800 < now) { tor->etaDLSpeedCalculatedAt = now; - tor->etaDLSpeed_Bps = ((tor->etaDLSpeedCalculatedAt + 4000) < now) ? + tor->etaDLSpeed_Bps = tor->etaDLSpeedCalculatedAt + 4000 < now ? pieceDownloadSpeed_Bps : /* if no recent previous speed, no need to smooth */ - ((tor->etaDLSpeed_Bps * 4.0) + pieceDownloadSpeed_Bps) / 5.0; /* smooth across 5 readings */ + (tor->etaDLSpeed_Bps * 4.0 + pieceDownloadSpeed_Bps) / 5.0; /* smooth across 5 readings */ } - if ((s->leftUntilDone > s->desiredAvailable) && (tor->info.webseedCount < 1)) + if (s->leftUntilDone > s->desiredAvailable && tor->info.webseedCount < 1) { s->eta = TR_ETA_NOT_AVAIL; } @@ -1458,12 +1458,12 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) } else { - if ((tor->etaULSpeedCalculatedAt + 800) < now) + if (tor->etaULSpeedCalculatedAt + 800 < now) { tor->etaULSpeedCalculatedAt = now; - tor->etaULSpeed_Bps = ((tor->etaULSpeedCalculatedAt + 4000) < now) ? + tor->etaULSpeed_Bps = tor->etaULSpeedCalculatedAt + 4000 < now ? pieceUploadSpeed_Bps : /* if no recent previous speed, no need to smooth */ - ((tor->etaULSpeed_Bps * 4.0) + pieceUploadSpeed_Bps) / 5.0; /* smooth across 5 readings */ + (tor->etaULSpeed_Bps * 4.0 + pieceUploadSpeed_Bps) / 5.0; /* smooth across 5 readings */ } if (tor->etaULSpeed_Bps == 0) @@ -1495,13 +1495,13 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) /* s->haveValid is here to make sure a torrent isn't marked 'finished' * when the user hits "uncheck all" prior to starting the torrent... */ - s->finished = tor->finishedSeedingByIdle || (seedRatioApplies && !seedRatioBytesLeft && s->haveValid); + s->finished = tor->finishedSeedingByIdle || (seedRatioApplies && seedRatioBytesLeft == 0 && s->haveValid != 0); if (!seedRatioApplies || s->finished) { s->seedRatioPercentDone = 1; } - else if (!seedRatioBytesGoal) /* impossible? safeguard for div by zero */ + else if (seedRatioBytesGoal == 0) /* impossible? safeguard for div by zero */ { s->seedRatioPercentDone = 0; } @@ -1527,7 +1527,7 @@ static uint64_t countFileBytesCompleted(tr_torrent const* tor, tr_file_index_t i uint64_t total = 0; tr_file const* f = &tor->info.files[index]; - if (f->length) + if (f->length != 0) { tr_block_index_t first; tr_block_index_t last; @@ -1581,7 +1581,7 @@ tr_file_stat* tr_torrentFiles(tr_torrent const* tor, tr_file_index_t* fileCount) { uint64_t const b = isSeed ? tor->info.files[i].length : countFileBytesCompleted(tor, i); walk->bytesCompleted = b; - walk->progress = tor->info.files[i].length > 0 ? ((float)b / tor->info.files[i].length) : 1.0f; + walk->progress = tor->info.files[i].length > 0 ? (float)b / tor->info.files[i].length : 1.0f; } if (fileCount != NULL) @@ -1729,7 +1729,7 @@ static void freeTorrent(tr_torrent* tor) /* resequence the queue positions */ t = NULL; - while ((t = tr_torrentNext(session, t))) + while ((t = tr_torrentNext(session, t)) != NULL) { if (t->queuePosition > tor->queuePosition) { @@ -2167,9 +2167,9 @@ static char const* getCompletionString(int type) static void fireCompletenessChange(tr_torrent* tor, tr_completeness status, bool wasRunning) { - assert((status == TR_LEECH) || (status == TR_SEED) || (status == TR_PARTIAL_SEED)); + assert(status == TR_LEECH || status == TR_SEED || status == TR_PARTIAL_SEED); - if (tor->completeness_func) + if (tor->completeness_func != NULL) { tor->completeness_func(tor, status, wasRunning, tor->completeness_func_user_data); } @@ -2244,7 +2244,7 @@ static void torrentCallScript(tr_torrent const* tor, char const* script) *newlinePos = '\0'; } - if (script && *script) + if (script != NULL && *script != '\0') { size_t i; char* cmd[] = @@ -2325,7 +2325,7 @@ static void torrentCallScript(tr_torrent const* tor, char const* script) signal(SIGCHLD, onSigCHLD); - if (!fork()) + if (fork() == 0) { for (i = 0; env[i] != NULL; ++i) { @@ -2539,7 +2539,7 @@ static void setFileDND(tr_torrent* tor, tr_file_index_t fileIndex, int doDownloa firstPieceDND = tor->info.files[i].dnd; - if (!i) + if (i == 0) { break; } @@ -2698,7 +2698,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ { err = 2; } - else if ((offset + length) > tr_torPieceCountBytes(tor, index)) + else if (offset + length > tr_torPieceCountBytes(tor, index)) { err = 3; } @@ -2711,7 +2711,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ err = 5; } - if (err) + if (err != 0) { tr_logAddTorDbg(tor, "index %lu offset %lu length %lu err %d\n", (unsigned long)index, (unsigned long)offset, (unsigned long)length, err); @@ -2740,7 +2740,7 @@ void tr_torGetFileBlockRange(tr_torrent const* tor, tr_file_index_t const file, *first = offset / tor->blockSize; - if (!f->length) + if (f->length == 0) { *last = *first; } @@ -2817,7 +2817,7 @@ bool tr_torrentPieceNeedsCheck(tr_torrent const* tor, tr_piece_index_t p) tr_info const* inf = tr_torrentInfo(tor); /* if we've never checked this piece, then it needs to be checked */ - if (!inf->pieces[p].timeChecked) + if (inf->pieces[p].timeChecked == 0) { return true; } @@ -2944,7 +2944,7 @@ bool tr_torrentSetAnnounceList(tr_torrent* tor, tr_tracker_info const* trackers_ /* if we had a tracker-related error on this torrent, * and that tracker's been removed, * then clear the error */ - if ((tor->error == TR_STAT_TRACKER_WARNING) || (tor->error == TR_STAT_TRACKER_ERROR)) + if (tor->error == TR_STAT_TRACKER_WARNING || tor->error == TR_STAT_TRACKER_ERROR) { bool clear = true; @@ -3493,7 +3493,7 @@ static void tr_torrentPieceCompleted(tr_torrent* tor, tr_piece_index_t pieceInde { tr_file const* file = &tor->info.files[i]; - if ((file->firstPiece <= pieceIndex) && (pieceIndex <= file->lastPiece)) + if (file->firstPiece <= pieceIndex && pieceIndex <= file->lastPiece) { if (tr_cpFileIsComplete(&tor->completion, i)) { @@ -3577,7 +3577,7 @@ bool tr_torrentFindFile2(tr_torrent const* tor, tr_file_index_t fileNum, char co } /* look in the incomplete dir... */ - if ((b == NULL) && (tor->incompleteDir != NULL)) + if (b == NULL && tor->incompleteDir != NULL) { char* filename = tr_buildPath(tor->incompleteDir, file->name, NULL); @@ -3596,7 +3596,7 @@ bool tr_torrentFindFile2(tr_torrent const* tor, tr_file_index_t fileNum, char co } /* look for a .part file in the incomplete dir... */ - if ((b == NULL) && (tor->incompleteDir != NULL)) + if (b == NULL && tor->incompleteDir != NULL) { char* filename = tr_buildPath(tor->incompleteDir, part, NULL); @@ -3678,7 +3678,7 @@ static void refreshCurrentDir(tr_torrent* tor) } assert(dir != NULL); - assert((dir == tor->downloadDir) || (dir == tor->incompleteDir)); + assert(dir == tor->downloadDir || dir == tor->incompleteDir); tor->currentDir = dir; } @@ -3763,11 +3763,11 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, int pos) walk = NULL; - while ((walk = tr_torrentNext(tor->session, walk))) + while ((walk = tr_torrentNext(tor->session, walk)) != NULL) { if (old_pos < pos) { - if ((old_pos <= walk->queuePosition) && (walk->queuePosition <= pos)) + if (old_pos <= walk->queuePosition && walk->queuePosition <= pos) { walk->queuePosition--; walk->anyDate = now; @@ -3776,7 +3776,7 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, int pos) if (old_pos > pos) { - if ((pos <= walk->queuePosition) && (walk->queuePosition < old_pos)) + if (pos <= walk->queuePosition && walk->queuePosition < old_pos) { walk->queuePosition++; walk->anyDate = now; @@ -3884,8 +3884,8 @@ void tr_torrentSetQueueStartCallback(tr_torrent* torrent, void (* callback)(tr_t static bool renameArgsAreValid(char const* oldpath, char const* newname) { - return (oldpath && *oldpath) && (newname && *newname) && (strcmp(newname, ".") != 0) && (strcmp(newname, "..") != 0) && - (strchr(newname, TR_PATH_DELIMITER) == NULL); + return oldpath != NULL && *oldpath != '\0' && newname != NULL && *newname != '\0' && strcmp(newname, ".") != 0 && + strcmp(newname, "..") != 0 && strchr(newname, TR_PATH_DELIMITER) == NULL; } static tr_file_index_t* renameFindAffectedFiles(tr_torrent* tor, char const* oldpath, size_t* setme_n) @@ -3919,7 +3919,7 @@ static int renamePath(tr_torrent* tor, char const* oldpath, char const* newname) char const* base; int err = 0; - if (!tr_torrentIsSeed(tor) && (tor->incompleteDir != NULL)) + if (!tr_torrentIsSeed(tor) && tor->incompleteDir != NULL) { base = tor->incompleteDir; } @@ -4075,7 +4075,7 @@ static void torrentRenamePath(void* vdata) error = renamePath(tor, oldpath, newname); - if (!error) + if (error == 0) { /* update tr_info.files */ for (i = 0; i < n; ++i) @@ -4084,7 +4084,7 @@ static void torrentRenamePath(void* vdata) } /* update tr_info.name if user changed the toplevel */ - if ((n == tor->info.fileCount) && (strchr(oldpath, '/') == NULL)) + if (n == tor->info.fileCount && strchr(oldpath, '/') == NULL) { tr_free(tor->info.name); tor->info.name = tr_strdup(newname); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index dc9d4b3b4..97e2ef263 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -243,7 +243,7 @@ struct tr_torrent static inline tr_torrent* tr_torrentNext(tr_session* session, tr_torrent* current) { - return current ? current->next : session->torrentList; + return current != NULL ? current->next : session->torrentList; } /* what piece index is this block in? */ @@ -296,22 +296,22 @@ static inline bool tr_torrentIsSeed(tr_torrent const* tor) static inline bool tr_torrentIsPrivate(tr_torrent const* tor) { - return (tor != NULL) && tor->info.isPrivate; + return tor != NULL && tor->info.isPrivate; } static inline bool tr_torrentAllowsPex(tr_torrent const* tor) { - return (tor != NULL) && (tor->session->isPexEnabled) && (!tr_torrentIsPrivate(tor)); + return tor != NULL && tor->session->isPexEnabled && !tr_torrentIsPrivate(tor); } static inline bool tr_torrentAllowsDHT(tr_torrent const* tor) { - return (tor != NULL) && (tr_sessionAllowsDHT(tor->session)) && (!tr_torrentIsPrivate(tor)); + return tor != NULL && tr_sessionAllowsDHT(tor->session) && !tr_torrentIsPrivate(tor); } static inline bool tr_torrentAllowsLPD(tr_torrent const* tor) { - return (tor != NULL) && (tr_sessionAllowsLPD(tor->session)) && (!tr_torrentIsPrivate(tor)); + return tor != NULL && tr_sessionAllowsLPD(tor->session) && !tr_torrentIsPrivate(tor); } /*** @@ -325,7 +325,7 @@ enum static inline bool tr_isTorrent(tr_torrent const* tor) { - return (tor != NULL) && (tor->magicNumber == TORRENT_MAGIC_NUMBER) && (tr_isSession(tor->session)); + return tor != NULL && tor->magicNumber == TORRENT_MAGIC_NUMBER && tr_isSession(tor->session); } /* set a flag indicating that the torrent's .resume file diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index 077009921..662d7a4b1 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -135,7 +135,7 @@ static void bootstrap_from_name(char const* name, tr_port port, int af) infop = info; - while (infop) + while (infop != NULL) { dht_ping_node(infop->ai_addr, infop->ai_addrlen); @@ -226,7 +226,7 @@ static void dht_bootstrap(void* closure) bootstrap_file = tr_buildPath(cl->session->configDir, "dht.bootstrap", NULL); - if (bootstrap_file) + if (bootstrap_file != NULL) { f = tr_sys_file_open(bootstrap_file, TR_SYS_FILE_READ, 0, NULL); } @@ -299,12 +299,12 @@ static void dht_bootstrap(void* closure) } } - if (cl->nodes) + if (cl->nodes != NULL) { tr_free(cl->nodes); } - if (cl->nodes6) + if (cl->nodes6 != NULL) { tr_free(cl->nodes6); } @@ -324,7 +324,7 @@ int tr_dhtInit(tr_session* ss) size_t len, len6; struct bootstrap_closure* cl; - if (session) /* already initialized */ + if (session != NULL) /* already initialized */ { return -1; } @@ -349,14 +349,12 @@ int tr_dhtInit(tr_session* ss) memcpy(myid, raw, len); } - if (ss->udp_socket != TR_BAD_SOCKET && - tr_variantDictFindRaw(&benc, TR_KEY_nodes, &raw, &len) && !(len % 6)) + if (ss->udp_socket != TR_BAD_SOCKET && tr_variantDictFindRaw(&benc, TR_KEY_nodes, &raw, &len) && len % 6 == 0) { nodes = tr_memdup(raw, len); } - if (ss->udp6_socket != TR_BAD_SOCKET && - tr_variantDictFindRaw(&benc, TR_KEY_nodes6, &raw, &len6) && !(len6 % 18)) + if (ss->udp6_socket != TR_BAD_SOCKET && tr_variantDictFindRaw(&benc, TR_KEY_nodes6, &raw, &len6) && len6 % 18 == 0) { nodes6 = tr_memdup(raw, len6); } @@ -433,7 +431,7 @@ void tr_dhtUninit(tr_session* ss) /* Since we only save known good nodes, avoid erasing older data if we don't know enough nodes. */ - if ((tr_dhtStatus(ss, AF_INET, NULL) < TR_DHT_FIREWALLED) && (tr_dhtStatus(ss, AF_INET6, NULL) < TR_DHT_FIREWALLED)) + if (tr_dhtStatus(ss, AF_INET, NULL) < TR_DHT_FIREWALLED && tr_dhtStatus(ss, AF_INET6, NULL) < TR_DHT_FIREWALLED) { tr_logAddNamedInfo("DHT", "Not saving nodes, DHT not ready"); } @@ -494,7 +492,7 @@ void tr_dhtUninit(tr_session* ss) bool tr_dhtEnabled(tr_session const* ss) { - return ss && (ss == session); + return ss != NULL && ss == session; } struct getstatus_closure @@ -538,7 +536,7 @@ int tr_dhtStatus(tr_session* session, int af, int* nodes_return) if (!tr_dhtEnabled(session) || (af == AF_INET && session->udp_socket == TR_BAD_SOCKET) || (af == AF_INET6 && session->udp6_socket == TR_BAD_SOCKET)) { - if (nodes_return) + if (nodes_return != NULL) { *nodes_return = 0; } @@ -553,7 +551,7 @@ int tr_dhtStatus(tr_session* session, int af, int* nodes_return) tr_wait_msec(50 /*msec*/); } - if (nodes_return) + if (nodes_return != NULL) { *nodes_return = closure.count; } @@ -642,7 +640,7 @@ static void callback(void* ignore UNUSED, int event, unsigned char const* info_h tr_sessionLock(session); tor = tr_torrentFindFromHash(session, info_hash); - if (tor && tr_torrentAllowsDHT(tor)) + if (tor != NULL && tr_torrentAllowsDHT(tor)) { size_t i, n; tr_pex* pex; @@ -671,7 +669,7 @@ static void callback(void* ignore UNUSED, int event, unsigned char const* info_h { tr_torrent* tor = tr_torrentFindFromHash(session, info_hash); - if (tor) + if (tor != NULL) { if (event == DHT_EVENT_SEARCH_DONE) { @@ -744,7 +742,7 @@ void tr_dhtUpkeep(tr_session* session) tr_torrent* tor = NULL; time_t const now = tr_time(); - while ((tor = tr_torrentNext(session, tor))) + while ((tor = tr_torrentNext(session, tor)) != NULL) { if (!tor->isRunning || !tr_torrentAllowsDHT(tor)) { diff --git a/libtransmission/tr-getopt-test.c b/libtransmission/tr-getopt-test.c index 58272f331..52026b87a 100644 --- a/libtransmission/tr-getopt-test.c +++ b/libtransmission/tr-getopt-test.c @@ -32,7 +32,7 @@ static int run_test(int argc, char const** argv, int expected_n, int* expected_c n = 0; tr_optind = 1; - while ((c = tr_getopt("summary", argc, argv, options, &optarg))) + while ((c = tr_getopt("summary", argc, argv, options, &optarg)) != TR_OPT_DONE) { check(n < expected_n); check_int_eq(expected_c[n], c); diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index 08cdc3bae..25214de64 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -27,7 +27,7 @@ static char const* getArgName(tr_option const* opt) { arg = ""; } - else if (opt->argName) + else if (opt->argName != NULL) { arg = opt->argName; } @@ -51,27 +51,27 @@ static int get_next_line_len(char const* description, int maxlen) end = maxlen < len ? maxlen : len; - while ((end > 0) && !isspace(description[end])) + while (end > 0 && !isspace(description[end])) { --end; } - return end ? end : len; + return end != 0 ? end : len; } static void getopts_usage_line(tr_option const* opt, int longWidth, int shortWidth, int argWidth) { int len; - char const* longName = opt->longName ? opt->longName : ""; - char const* shortName = opt->shortName ? opt->shortName : ""; + char const* longName = opt->longName != NULL ? opt->longName : ""; + char const* shortName = opt->shortName != NULL ? opt->shortName : ""; char const* arg = getArgName(opt); int const d_indent = shortWidth + longWidth + argWidth + 7; int const d_width = 80 - d_indent; char const* d = opt->description; - printf(" %s%-*s %s%-*s %-*s ", (shortName && *shortName ? "-" : " "), shortWidth, shortName, - (longName && *longName ? "--" : " "), longWidth, longName, argWidth, arg); + printf(" %s%-*s %s%-*s %-*s ", (shortName != NULL && *shortName != '\0') ? "-" : " ", shortWidth, shortName, + (longName != NULL && *longName != '\0') ? "--" : " ", longWidth, longName, argWidth, arg); len = get_next_line_len(d, d_width); printf("%*.*s\n", len, len, d); @@ -82,7 +82,7 @@ static void getopts_usage_line(tr_option const* opt, int longWidth, int shortWid ++d; } - while ((len = get_next_line_len(d, d_width))) + while ((len = get_next_line_len(d, d_width)) != 0) { printf("%*.*s%*.*s\n", d_indent, d_indent, "", len, len, d); d += len; @@ -98,17 +98,17 @@ static void maxWidth(struct tr_option const* o, int* longWidth, int* shortWidth, { char const* arg; - if (o->longName) + if (o->longName != NULL) { *longWidth = MAX(*longWidth, (int)strlen(o->longName)); } - if (o->shortName) + if (o->shortName != NULL) { *shortWidth = MAX(*shortWidth, (int)strlen(o->shortName)); } - if ((arg = getArgName(o))) + if ((arg = getArgName(o)) != NULL) { *argWidth = MAX(*argWidth, (int)strlen(arg)); } @@ -122,7 +122,7 @@ void tr_getopt_usage(char const* progName, char const* description, struct tr_op struct tr_option help; struct tr_option const* o; - for (o = opts; o->val; ++o) + for (o = opts; o->val != 0; ++o) { maxWidth(o, &longWidth, &shortWidth, &argWidth); } @@ -143,7 +143,7 @@ void tr_getopt_usage(char const* progName, char const* description, struct tr_op printf("\n\nOptions:\n"); getopts_usage_line(&help, longWidth, shortWidth, argWidth); - for (o = opts; o->val; ++o) + for (o = opts; o->val != 0; ++o) { getopts_usage_line(o, longWidth, shortWidth, argWidth); } @@ -157,11 +157,11 @@ static tr_option const* findOption(tr_option const* opts, char const* str, char tr_option const* match = NULL; /* find the longest matching option */ - for (o = opts; o->val; ++o) + for (o = opts; o->val != 0; ++o) { - size_t len = o->longName ? strlen(o->longName) : 0; + size_t len = o->longName != NULL ? strlen(o->longName) : 0; - if ((matchlen < len) && (str[0] == '-') && (str[1] == '-') && strncmp(str + 2, o->longName, len) == 0 && + if (matchlen < len && str[0] == '-' && str[1] == '-' && strncmp(str + 2, o->longName, len) == 0 && (str[len + 2] == '\0' || (o->has_arg && str[len + 2] == '='))) { matchlen = len; @@ -169,10 +169,9 @@ static tr_option const* findOption(tr_option const* opts, char const* str, char arg = str[len + 2] == '=' ? str + len + 3 : NULL; } - len = o->shortName ? strlen(o->shortName) : 0; + len = o->shortName != NULL ? strlen(o->shortName) : 0; - if ((matchlen < len) && (str[0] == '-') && strncmp(str + 1, o->shortName, len) == 0 && - (str[len + 1] == '\0' || o->has_arg)) + if (matchlen < len && str[0] == '-' && strncmp(str + 1, o->shortName, len) == 0 && (str[len + 1] == '\0' || o->has_arg)) { matchlen = len; match = o; @@ -194,7 +193,7 @@ static tr_option const* findOption(tr_option const* opts, char const* str, char } } - if (setme_arg) + if (setme_arg != NULL) { *setme_arg = arg; } @@ -228,7 +227,7 @@ int tr_getopt(char const* usage, int argc, char const* const* argv, tr_option co o = findOption(opts, argv[tr_optind], &arg); - if (!o) + if (o == NULL) { /* let the user know we got an unknown option... */ *setme_optarg = argv[tr_optind++]; @@ -238,7 +237,7 @@ int tr_getopt(char const* usage, int argc, char const* const* argv, tr_option co if (!o->has_arg) { /* no argument needed for this option, so we're done */ - if (arg) + if (arg != NULL) { return TR_OPT_ERR; } @@ -249,7 +248,7 @@ int tr_getopt(char const* usage, int argc, char const* const* argv, tr_option co } /* option needed an argument, and it was embedded in this string */ - if (arg) + if (arg != NULL) { *setme_optarg = arg; ++tr_optind; @@ -262,7 +261,7 @@ int tr_getopt(char const* usage, int argc, char const* const* argv, tr_option co return TR_OPT_ERR; } - if (findOption(opts, argv[tr_optind], NULL)) + if (findOption(opts, argv[tr_optind], NULL) != NULL) { return TR_OPT_ERR; } diff --git a/libtransmission/tr-lpd.c b/libtransmission/tr-lpd.c index c7313433b..0d6921d4b 100644 --- a/libtransmission/tr-lpd.c +++ b/libtransmission/tr-lpd.c @@ -296,7 +296,7 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED) struct ip_mreq mcastReq; int const opt_on = 1, opt_off = 0; - if (session) /* already initialized */ + if (session != NULL) /* already initialized */ { return -1; } @@ -444,7 +444,7 @@ void tr_lpdUninit(tr_session* ss) bool tr_lpdEnabled(tr_session const* ss) { - return ss && (ss == session); + return ss != NULL && ss == session; } /** @@ -499,7 +499,7 @@ bool tr_lpdSendAnnounce(tr_torrent const* t) } /* make sure the hash string is normalized, just in case */ - for (i = 0; i < sizeof hashString; i++) + for (i = 0; i < sizeof(hashString); i++) { hashString[i] = toupper(t->info.hashString[i]); } @@ -629,7 +629,7 @@ static int tr_lpdAnnounceMore(time_t const now, int const interval) return -1; } - while ((tor = tr_torrentNext(session, tor)) && tr_sessionAllowsLPD(session)) + while ((tor = tr_torrentNext(session, tor)) != NULL && tr_sessionAllowsLPD(session)) { if (tr_isTorrent(tor)) { diff --git a/libtransmission/tr-udp.c b/libtransmission/tr-udp.c index 25aa326f9..6764814dd 100644 --- a/libtransmission/tr-udp.c +++ b/libtransmission/tr-udp.c @@ -50,7 +50,7 @@ THE SOFTWARE. #define SEND_BUFFER_SIZE (1 * 1024 * 1024) #define SMALL_BUFFER_SIZE (32 * 1024) -static void set_socket_buffers(tr_socket_t fd, int large) +static void set_socket_buffers(tr_socket_t fd, bool large) { int size, rbuf, sbuf, rc; socklen_t rbuf_len = sizeof(rbuf), sbuf_len = sizeof(sbuf); @@ -138,7 +138,7 @@ static void rebind_ipv6(tr_session* ss, bool force) No way to fix that without some surgery to the DHT code itself. */ if (ipv6 == NULL || (!force && ss->udp6_socket == TR_BAD_SOCKET)) { - if (ss->udp6_bound) + if (ss->udp6_bound != NULL) { free(ss->udp6_bound); ss->udp6_bound = NULL; @@ -168,7 +168,7 @@ static void rebind_ipv6(tr_session* ss, bool force) memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; - if (ipv6) + if (ipv6 != NULL) { memcpy(&sin6.sin6_addr, ipv6, 16); } @@ -176,7 +176,7 @@ static void rebind_ipv6(tr_session* ss, bool force) sin6.sin6_port = htons(ss->udp_port); public_addr = tr_sessionGetPublicAddress(ss, TR_AF_INET6, &is_default); - if (public_addr && !is_default) + if (public_addr != NULL && !is_default) { sin6.sin6_addr = public_addr->addr.addr6; } @@ -210,7 +210,7 @@ static void rebind_ipv6(tr_session* ss, bool force) ss->udp6_bound = malloc(16); } - if (ss->udp6_bound) + if (ss->udp6_bound != NULL) { memcpy(ss->udp6_bound, ipv6, 16); } @@ -227,7 +227,7 @@ fail: tr_netCloseSocket(s); } - if (ss->udp6_bound) + if (ss->udp6_bound != NULL) { free(ss->udp6_bound); ss->udp6_bound = NULL; @@ -269,7 +269,7 @@ static void event_callback(evutil_socket_t s, short type UNUSED, void* sv) { rc = tau_handle_message(ss, buf, rc); - if (!rc) + if (rc == 0) { tr_logAddNamedDbg("UDP", "Couldn't parse UDP tracker packet."); } @@ -280,7 +280,7 @@ static void event_callback(evutil_socket_t s, short type UNUSED, void* sv) { rc = tr_utpPacket(buf, rc, (struct sockaddr*)&from, fromlen, ss); - if (!rc) + if (rc == 0) { tr_logAddNamedDbg("UDP", "Unexpected UDP packet"); } @@ -318,7 +318,7 @@ void tr_udpInit(tr_session* ss) sin.sin_family = AF_INET; public_addr = tr_sessionGetPublicAddress(ss, TR_AF_INET, &is_default); - if (public_addr && !is_default) + if (public_addr != NULL && !is_default) { memcpy(&sin.sin_addr, &public_addr->addr.addr4, sizeof(struct in_addr)); } @@ -365,12 +365,12 @@ ipv6: tr_dhtInit(ss); } - if (ss->udp_event) + if (ss->udp_event != NULL) { event_add(ss->udp_event, NULL); } - if (ss->udp6_event) + if (ss->udp6_event != NULL) { event_add(ss->udp6_event, NULL); } @@ -386,7 +386,7 @@ void tr_udpUninit(tr_session* ss) ss->udp_socket = TR_BAD_SOCKET; } - if (ss->udp_event) + if (ss->udp_event != NULL) { event_free(ss->udp_event); ss->udp_event = NULL; @@ -398,13 +398,13 @@ void tr_udpUninit(tr_session* ss) ss->udp6_socket = TR_BAD_SOCKET; } - if (ss->udp6_event) + if (ss->udp6_event != NULL) { event_free(ss->udp6_event); ss->udp6_event = NULL; } - if (ss->udp6_bound) + if (ss->udp6_bound != NULL) { free(ss->udp6_bound); ss->udp6_bound = NULL; diff --git a/libtransmission/tr-utp.c b/libtransmission/tr-utp.c index 3b65dea5a..3ab795ec2 100644 --- a/libtransmission/tr-utp.c +++ b/libtransmission/tr-utp.c @@ -176,7 +176,7 @@ static void timer_callback(evutil_socket_t s UNUSED, short type UNUSED, void* cl int tr_utpPacket(unsigned char const* buf, size_t buflen, struct sockaddr const* from, socklen_t fromlen, tr_session* ss) { - if (!ss->isClosed && !utp_timer) + if (!ss->isClosed && utp_timer == NULL) { utp_timer = evtimer_new(ss->event_base, timer_callback, ss); @@ -193,7 +193,7 @@ int tr_utpPacket(unsigned char const* buf, size_t buflen, struct sockaddr const* void tr_utpClose(tr_session* session UNUSED) { - if (utp_timer) + if (utp_timer != NULL) { evtimer_del(utp_timer); utp_timer = NULL; diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 1e4c8d3f2..9f67eab19 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -150,7 +150,7 @@ typedef int tr_pipe_end_t; typedef struct tr_event_handle { - uint8_t die; + bool die; tr_pipe_end_t fds[2]; tr_lock* lock; tr_session* session; @@ -203,7 +203,7 @@ static void readFromPipe(evutil_socket_t fd, short eventType, void* veh) size_t const nwant = sizeof(data); ev_ssize_t const ngot = piperead(fd, &data, nwant); - if (!eh->die && (ngot == (ev_ssize_t)nwant)) + if (!eh->die && ngot == (ev_ssize_t)nwant) { dbgmsg("invoking function in libevent thread"); (data.func)(data.user_data); @@ -363,7 +363,7 @@ void tr_runInEventThread(tr_session* session, void (* func)(void*), void* user_d tr_lockUnlock(e->lock); - if ((res_1 == -1) || (res_2 == -1)) + if (res_1 == -1 || res_2 == -1) { tr_logAddError("Unable to write to libtransmisison event queue: %s", tr_strerror(errno)); } diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index ddab9e359..893cdd148 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -46,7 +46,7 @@ struct tr_upnp struct IGDdatas data; int port; char lanaddr[16]; - unsigned int isMapped; + bool isMapped; tr_upnp_state state; }; @@ -66,7 +66,7 @@ tr_upnp* tr_upnpInit(void) void tr_upnpClose(tr_upnp* handle) { assert(!handle->isMapped); - assert((handle->state == TR_UPNP_IDLE) || (handle->state == TR_UPNP_ERR) || (handle->state == TR_UPNP_DISCOVER)); + assert(handle->state == TR_UPNP_IDLE || handle->state == TR_UPNP_ERR || handle->state == TR_UPNP_DISCOVER); if (handle->hasDiscovered) { @@ -151,7 +151,7 @@ static int tr_upnpAddPortMapping(tr_upnp const* handle, char const* proto, tr_po proto, NULL); #endif - if (err) + if (err != 0) { tr_logAddNamedDbg(getKey(), "%s Port forwarding failed with error %d (errno %d - %s)", proto, err, errno, tr_strerror(errno)); @@ -182,11 +182,11 @@ enum UPNP_IGD_INVALID = 3 }; -int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) +int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck) { int ret; - if (isEnabled && (handle->state == TR_UPNP_DISCOVER)) + if (isEnabled && handle->state == TR_UPNP_DISCOVER) { struct UPNPDev* devlist; @@ -214,7 +214,7 @@ int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) if (handle->state == TR_UPNP_IDLE) { - if (handle->isMapped && (!isEnabled || (handle->port != port))) + if (handle->isMapped && (!isEnabled || handle->port != port)) { handle->state = TR_UPNP_UNMAP; } @@ -222,8 +222,8 @@ int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) if (isEnabled && handle->isMapped && doPortCheck) { - if ((tr_upnpGetSpecificPortMappingEntry(handle, "TCP") != UPNPCOMMAND_SUCCESS) || - (tr_upnpGetSpecificPortMappingEntry(handle, "UDP") != UPNPCOMMAND_SUCCESS)) + if (tr_upnpGetSpecificPortMappingEntry(handle, "TCP") != UPNPCOMMAND_SUCCESS || + tr_upnpGetSpecificPortMappingEntry(handle, "UDP") != UPNPCOMMAND_SUCCESS) { tr_logAddNamedInfo(getKey(), _("Port %d isn't forwarded"), handle->port); handle->isMapped = false; @@ -238,7 +238,7 @@ int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) tr_logAddNamedInfo(getKey(), _("Stopping port forwarding through \"%s\", service \"%s\""), handle->urls.controlURL, handle->data.first.servicetype); - handle->isMapped = 0; + handle->isMapped = false; handle->state = TR_UPNP_IDLE; handle->port = -1; } @@ -257,7 +257,7 @@ int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) int err_udp = -1; errno = 0; - if (!handle->urls.controlURL) + if (handle->urls.controlURL == NULL) { handle->isMapped = 0; } @@ -269,7 +269,7 @@ int tr_upnpPulse(tr_upnp* handle, int port, int isEnabled, int doPortCheck) err_tcp = tr_upnpAddPortMapping(handle, "TCP", port, desc); err_udp = tr_upnpAddPortMapping(handle, "UDP", port, desc); - handle->isMapped = !err_tcp | !err_udp; + handle->isMapped = err_tcp == 0 || err_udp == 0; } tr_logAddNamedInfo(getKey(), _("Port forwarding through \"%s\", service \"%s\". (local address: %s:%d)"), diff --git a/libtransmission/upnp.h b/libtransmission/upnp.h index 207b51306..ace7f1de8 100644 --- a/libtransmission/upnp.h +++ b/libtransmission/upnp.h @@ -23,6 +23,6 @@ tr_upnp* tr_upnpInit(void); void tr_upnpClose(tr_upnp*); -int tr_upnpPulse(tr_upnp*, int port, int isEnabled, int doPortCheck); +int tr_upnpPulse(tr_upnp*, int port, bool isEnabled, bool doPortCheck); /* @} */ diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 213c5435b..5201f287a 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -113,7 +113,7 @@ static int test_utf8(void) in = "\x92\xE0\xE3\xA4\xAD\xAE \xA1\xEB\xE2\xEC \x81\xAE\xA3\xAE\xAC"; out = tr_utf8clean(in, 17); check(out != NULL); - check((strlen(out) == 17) || (strlen(out) == 33)); + check(strlen(out) == 17 || strlen(out) == 33); check(tr_utf8_validate(out, TR_BAD_SIZE, NULL)); tr_free(out); @@ -128,14 +128,14 @@ static int test_utf8(void) in = "\xF4\x00\x81\x82"; out = tr_utf8clean(in, 4); check(out != NULL); - check((strlen(out) == 1) || (strlen(out) == 2)); + check(strlen(out) == 1 || strlen(out) == 2); check(tr_utf8_validate(out, TR_BAD_SIZE, NULL)); tr_free(out); in = "\xF4\x33\x81\x82"; out = tr_utf8clean(in, 4); check(out != NULL); - check((strlen(out) == 4) || (strlen(out) == 7)); + check(strlen(out) == 4 || strlen(out) == 7); check(tr_utf8_validate(out, TR_BAD_SIZE, NULL)); tr_free(out); @@ -322,14 +322,14 @@ static int test_array(void) for (i = 0; i < n; ++i) { - check_int_eq((i < 5 ? i : i + 1), array[i]); + check_int_eq(i < 5 ? i : i + 1, array[i]); } tr_removeElementFromArray(array, 0u, sizeof(size_t), n--); for (i = 0; i < n; ++i) { - check_int_eq((i < 4 ? i + 1 : i + 2), array[i]); + check_int_eq(i < 4 ? i + 1 : i + 2, array[i]); } tr_removeElementFromArray(array, n - 1, sizeof(size_t), n); @@ -337,7 +337,7 @@ static int test_array(void) for (i = 0; i < n; ++i) { - check_int_eq((i < 4 ? i + 1 : i + 2), array[i]); + check_int_eq(i < 4 ? i + 1 : i + 2, array[i]); } return 0; diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 65f55814b..499dc6447 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -72,7 +72,7 @@ struct tm* tr_localtime_r(time_t const* _clock, struct tm* _result) struct tm* p = localtime(_clock); - if (p) + if (p != NULL) { *(_result) = *p; } @@ -124,12 +124,12 @@ int tr_gettimeofday(struct timeval* tv) void* tr_malloc(size_t size) { - return size ? malloc(size) : NULL; + return size != 0 ? malloc(size) : NULL; } void* tr_malloc0(size_t size) { - return size ? calloc(1, size) : NULL; + return size != 0 ? calloc(1, size) : NULL; } void* tr_realloc(void* p, size_t size) @@ -167,9 +167,9 @@ char const* tr_strip_positional_args(char const* str) static size_t bufsize = 0; static char* buf = NULL; char const* in = str; - size_t const len = str ? strlen(str) : 0; + size_t const len = str != NULL ? strlen(str) : 0; - if (!buf || (bufsize < len)) + if (buf == NULL || bufsize < len) { bufsize = len * 2 + 1; buf = tr_renew(char, buf, bufsize); @@ -179,7 +179,7 @@ char const* tr_strip_positional_args(char const* str) { *out++ = *str; - if ((*str == '%') && isdigit(str[1])) + if (*str == '%' && isdigit(str[1])) { char const* tmp = str + 1; @@ -194,7 +194,7 @@ char const* tr_strip_positional_args(char const* str) } } - if ((*str == '%') && (str[1] == '\'')) + if (*str == '%' && str[1] == '\'') { str = str + 1; } @@ -300,7 +300,7 @@ char* tr_buildPath(char const* first_element, ...) va_start(vl, first_element); element = first_element; - while (element) + while (element != NULL) { bufLen += strlen(element) + 1; element = va_arg(vl, char const*); @@ -318,7 +318,7 @@ char* tr_buildPath(char const* first_element, ...) va_start(vl, first_element); element = first_element; - while (element) + while (element != NULL) { size_t const elementLen = strlen(element); memcpy(pch, element, elementLen); @@ -346,7 +346,7 @@ int64_t tr_getDirFreeSpace(char const* dir) { int64_t free_space; - if (!dir || !*dir) + if (dir == NULL || *dir == '\0') { errno = EINVAL; free_space = -1; @@ -395,7 +395,7 @@ char* tr_strndup(void const* in, size_t len) { out = tr_strdup(in); } - else if (in) + else if (in != NULL) { out = tr_malloc(len + 1); @@ -416,14 +416,15 @@ char const* tr_memmem(char const* haystack, size_t haystacklen, char const* need return memmem(haystack, haystacklen, needle, needlelen); #else + size_t i; - if (!needlelen) + if (needlelen == 0) { return haystack; } - if (needlelen > haystacklen || !haystack || !needle) + if (needlelen > haystacklen || haystack == NULL || needle == NULL) { return NULL; } @@ -474,17 +475,17 @@ char const* tr_strerror(int i) int tr_strcmp0(char const* str1, char const* str2) { - if (str1 && str2) + if (str1 != NULL && str2 != NULL) { return strcmp(str1, str2); } - if (str1) + if (str1 != NULL) { return 1; } - if (str2) + if (str2 != NULL) { return -1; } @@ -541,7 +542,7 @@ char* tr_strstrip(char* str) size_t pos; size_t len = strlen(str); - while (len && isspace(str[len - 1])) + while (len != 0 && isspace(str[len - 1])) { --len; } @@ -564,12 +565,12 @@ bool tr_str_has_suffix(char const* str, char const* suffix) size_t str_len; size_t suffix_len; - if (!str) + if (str == NULL) { return false; } - if (!suffix) + if (suffix == NULL) { return true; } @@ -668,7 +669,7 @@ size_t tr_strlcpy(char* dst, void const* src, size_t siz) *d = '\0'; /* NUL-terminate dst */ } - while (*s++) + while (*s++ != '\0') { } } @@ -1141,7 +1142,7 @@ static char* to_utf8(const char* in, size_t inlen) size_t const buflen = inlen * 4 + 10; char* out = tr_new(char, buflen); - for (i = 0; !ret && i < encoding_count; ++i) + for (i = 0; ret == NULL && i < encoding_count; ++i) { #ifdef ICONV_SECOND_ARGUMENT_IS_CONST char const* inbuf = in; @@ -1401,7 +1402,7 @@ static bool parseNumberSection(char const* str, size_t len, struct number_range* errno = 0; a = b = strtol(tmp, &end, 10); - if (errno || (end == tmp)) + if (errno != 0 || end == tmp) { success = false; } @@ -1414,11 +1415,11 @@ static bool parseNumberSection(char const* str, size_t len, struct number_range* char const* pch = end + 1; b = strtol(pch, &end, 10); - if (errno || (pch == end)) + if (errno != 0 || pch == end) { success = false; } - else if (*end) /* trailing data */ + else if (*end != '\0') /* trailing data */ { success = false; } @@ -1462,12 +1463,12 @@ int* tr_parseNumberRange(char const* str_in, size_t len, int* setmeCount) walk = str; - while (walk && *walk && success) + while (walk != NULL && *walk != '\0' && success) { struct number_range range; char const* pch = strchr(walk, ','); - if (pch) + if (pch != NULL) { success = parseNumberSection(walk, (size_t)(pch - walk), &range); walk = pch + 1; @@ -1539,7 +1540,7 @@ int* tr_parseNumberRange(char const* str_in, size_t len, int* setmeCount) { for (i = n = 0; i < n2; ++i) { - if (!n || uniq[n - 1] != sorted[i]) + if (n == 0 || uniq[n - 1] != sorted[i]) { uniq[n++] = sorted[i]; } @@ -1570,9 +1571,9 @@ double tr_truncd(double x, int precision) int const max_precision = (int)log10(1.0 / DBL_EPSILON) - 1; tr_snprintf(buf, sizeof(buf), "%.*f", max_precision, x); - if ((pt = strstr(buf, localeconv()->decimal_point))) + if ((pt = strstr(buf, localeconv()->decimal_point)) != NULL) { - pt[precision ? precision + 1 : 0] = '\0'; + pt[precision != 0 ? precision + 1 : 0] = '\0'; } return atof(buf); @@ -1737,7 +1738,7 @@ void* tr_valloc(size_t bufLen) void* buf = NULL; static size_t pageSize = 0; - if (!pageSize) + if (pageSize == 0) { #if defined(HAVE_GETPAGESIZE) && !defined(_WIN32) pageSize = (size_t)getpagesize(); @@ -1755,9 +1756,9 @@ void* tr_valloc(size_t bufLen) #ifdef HAVE_POSIX_MEMALIGN - if (!buf) + if (buf == NULL) { - if (posix_memalign(&buf, pageSize, allocLen)) + if (posix_memalign(&buf, pageSize, allocLen) != 0) { buf = NULL; /* just retry with valloc/malloc */ } @@ -1767,14 +1768,14 @@ void* tr_valloc(size_t bufLen) #ifdef HAVE_VALLOC - if (!buf) + if (buf == NULL) { buf = valloc(allocLen); } #endif - if (!buf) + if (buf == NULL) { buf = tr_malloc(allocLen); } diff --git a/libtransmission/variant-benc.c b/libtransmission/variant-benc.c index eda4c5997..eff009634 100644 --- a/libtransmission/variant-benc.c +++ b/libtransmission/variant-benc.c @@ -65,12 +65,12 @@ int tr_bencParseInt(uint8_t const* buf, uint8_t const* bufend, uint8_t const** s errno = 0; val = evutil_strtoll(begin, &endptr, 10); - if (errno || (endptr != end)) /* incomplete parse */ + if (errno != 0 || endptr != end) /* incomplete parse */ { return EILSEQ; } - if (val && *(char const*)begin == '0') /* no leading zeroes! */ + if (val != 0 && *(char const*)begin == '0') /* no leading zeroes! */ { return EILSEQ; } @@ -115,7 +115,7 @@ int tr_bencParseStr(uint8_t const* buf, uint8_t const* bufend, uint8_t const** s errno = 0; len = strtoul((char const*)buf, &ulend, 10); - if (errno || ulend != end) + if (errno != 0 || ulend != end) { goto err; } @@ -123,7 +123,7 @@ int tr_bencParseStr(uint8_t const* buf, uint8_t const* bufend, uint8_t const** s strbegin = (uint8_t const*)end + 1; strend = strbegin + len; - if ((strend < strbegin) || (strend > bufend)) + if (strend < strbegin || strend > bufend) { goto err; } @@ -156,7 +156,7 @@ static tr_variant* get_node(tr_ptrArray* stack, tr_quark* key, tr_variant* top, { node = tr_variantListAdd(parent); } - else if (*key && tr_variantIsDict(parent)) + else if (*key != 0 && tr_variantIsDict(parent)) { node = tr_variantDictAdd(parent, *key); *key = 0; @@ -192,7 +192,7 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t err = EILSEQ; } - if (err) + if (err != 0) { break; } @@ -203,14 +203,14 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t uint8_t const* end; tr_variant* v; - if ((err = tr_bencParseInt(buf, bufend, &end, &val))) + if ((err = tr_bencParseInt(buf, bufend, &end, &val)) != 0) { break; } buf = end; - if ((v = get_node(&stack, &key, top, &err))) + if ((v = get_node(&stack, &key, top, &err)) != NULL) { tr_variantInitInt(v, val); } @@ -221,7 +221,7 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t ++buf; - if ((v = get_node(&stack, &key, top, &err))) + if ((v = get_node(&stack, &key, top, &err)) != NULL) { tr_variantInitList(v, 0); tr_ptrArrayAppend(&stack, v); @@ -233,7 +233,7 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t ++buf; - if ((v = get_node(&stack, &key, top, &err))) + if ((v = get_node(&stack, &key, top, &err)) != NULL) { tr_variantInitDict(v, 0); tr_ptrArrayAppend(&stack, v); @@ -243,7 +243,7 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t { ++buf; - if (tr_ptrArrayEmpty(&stack) || (key != 0)) + if (tr_ptrArrayEmpty(&stack) || key != 0) { err = EILSEQ; break; @@ -265,18 +265,18 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t uint8_t const* str; size_t str_len; - if ((err = tr_bencParseStr(buf, bufend, &end, &str, &str_len))) + if ((err = tr_bencParseStr(buf, bufend, &end, &str, &str_len)) != 0) { break; } buf = end; - if (!key && !tr_ptrArrayEmpty(&stack) && tr_variantIsDict(tr_ptrArrayBack(&stack))) + if (key == 0 && !tr_ptrArrayEmpty(&stack) && tr_variantIsDict(tr_ptrArrayBack(&stack))) { key = tr_quark_new(str, str_len); } - else if ((v = get_node(&stack, &key, top, &err))) + else if ((v = get_node(&stack, &key, top, &err)) != NULL) { tr_variantInitStr(v, str, str_len); } diff --git a/libtransmission/variant-json.c b/libtransmission/variant-json.c index 009467ee3..ce62f813b 100644 --- a/libtransmission/variant-json.c +++ b/libtransmission/variant-json.c @@ -54,7 +54,7 @@ static tr_variant* get_node(struct jsonsl_st* jsn) parent = tr_ptrArrayEmpty(&data->stack) ? NULL : tr_ptrArrayBack(&data->stack); - if (!parent) + if (parent == NULL) { node = data->top; } @@ -62,7 +62,7 @@ static tr_variant* get_node(struct jsonsl_st* jsn) { node = tr_variantListAdd(parent); } - else if (tr_variantIsDict(parent) && (data->key != NULL)) + else if (tr_variantIsDict(parent) && data->key != NULL) { node = tr_variantDictAdd(parent, tr_quark_new(data->key, data->keylen)); @@ -77,7 +77,7 @@ static void error_handler(jsonsl_t jsn, jsonsl_error_t error, struct jsonsl_stat { struct json_wrapper_data* data = jsn->data; - if (data->source) + if (data->source != NULL) { tr_logAddError("JSON parse failed in %s at pos %zu: %s -- remaining text \"%.16s\"", data->source, jsn->pos, jsonsl_strerror(error), buf); @@ -139,15 +139,15 @@ static bool decode_hex_string(char const* in, unsigned int* setme) { val <<= 4; - if (('0' <= *in) && (*in <= '9')) + if ('0' <= *in && *in <= '9') { val += (*in - '0'); } - else if (('a' <= *in) && (*in <= 'f')) + else if ('a' <= *in && *in <= 'f') { val += (*in - 'a') + 10u; } - else if (('A' <= *in) && (*in <= 'F')) + else if ('A' <= *in && *in <= 'F') { val += (*in - 'A') + 10u; } @@ -314,31 +314,31 @@ static void action_callback_POP(jsonsl_t jsn, jsonsl_action_t action UNUSED, str data->has_content = true; data->key = extract_string(jsn, state, &data->keylen, data->keybuf); } - else if ((state->type == JSONSL_T_LIST) || (state->type == JSONSL_T_OBJECT)) + else if (state->type == JSONSL_T_LIST || state->type == JSONSL_T_OBJECT) { tr_ptrArrayPop(&data->stack); } else if (state->type == JSONSL_T_SPECIAL) { - if (state->special_flags & JSONSL_SPECIALf_NUMNOINT) + if ((state->special_flags & JSONSL_SPECIALf_NUMNOINT) != 0) { char const* begin = jsn->base + state->pos_begin; data->has_content = true; tr_variantInitReal(get_node(jsn), strtod(begin, NULL)); } - else if (state->special_flags & JSONSL_SPECIALf_NUMERIC) + else if ((state->special_flags & JSONSL_SPECIALf_NUMERIC) != 0) { char const* begin = jsn->base + state->pos_begin; data->has_content = true; tr_variantInitInt(get_node(jsn), evutil_strtoll(begin, NULL, 10)); } - else if (state->special_flags & JSONSL_SPECIALf_BOOLEAN) + else if ((state->special_flags & JSONSL_SPECIALf_BOOLEAN) != 0) { bool const b = (state->special_flags & JSONSL_SPECIALf_TRUE) != 0; data->has_content = true; tr_variantInitBool(get_node(jsn), b); } - else if (state->special_flags & JSONSL_SPECIALf_NULL) + else if ((state->special_flags & JSONSL_SPECIALf_NULL) != 0) { data->has_content = true; tr_variantInitQuark(get_node(jsn), TR_KEY_NONE); @@ -372,13 +372,13 @@ int tr_jsonParse(char const* source, void const* vbuf, size_t len, tr_variant* s jsonsl_feed(jsn, vbuf, len); /* EINVAL if there was no content */ - if (!data.error && !data.has_content) + if (data.error == 0 && !data.has_content) { data.error = EINVAL; } /* maybe set the end ptr */ - if (setme_end) + if (setme_end != NULL) { *setme_end = ((char const*)vbuf) + jsn->pos; } @@ -414,7 +414,7 @@ static void jsonIndent(struct jsonWalk* data) { static char buf[1024] = { '\0' }; - if (!*buf) + if (*buf == '\0') { memset(buf, ' ', sizeof(buf)); buf[0] = '\n'; @@ -428,7 +428,7 @@ static void jsonIndent(struct jsonWalk* data) static void jsonChildFunc(struct jsonWalk* data) { - if (data->parents && data->parents->data) + if (data->parents != NULL && data->parents->data != NULL) { struct ParentState* pstate = data->parents->data; @@ -438,7 +438,7 @@ static void jsonChildFunc(struct jsonWalk* data) { int const i = pstate->childIndex++; - if (!(i % 2)) + if (i % 2 == 0) { evbuffer_add(data->out, ": ", data->doIndent ? 2 : 1); } @@ -609,7 +609,7 @@ static void jsonStringFunc(tr_variant const* val, void* vdata) UTF32* u32 = buf; ConversionResult result = ConvertUTF8toUTF32(&tmp, end, &u32, buf + 1, 0); - if (((result == conversionOK) || (result == targetExhausted)) && (tmp != it)) + if ((result == conversionOK || result == targetExhausted) && tmp != it) { outwalk += tr_snprintf(outwalk, outend - outwalk, "\\u%04x", (unsigned int)buf[0]); it = tmp - 1; @@ -634,7 +634,7 @@ static void jsonDictBeginFunc(tr_variant const* val, void* vdata) jsonPushParent(data, val); evbuffer_add(data->out, "{", 1); - if (val->val.l.count) + if (val->val.l.count != 0) { jsonIndent(data); } @@ -648,7 +648,7 @@ static void jsonListBeginFunc(tr_variant const* val, void* vdata) jsonPushParent(data, val); evbuffer_add(data->out, "[", 1); - if (nChildren) + if (nChildren != 0) { jsonIndent(data); } @@ -699,7 +699,7 @@ void tr_variantToBufJson(tr_variant const* top, struct evbuffer* buf, bool lean) tr_variantWalk(top, &walk_funcs, &data, true); - if (evbuffer_get_length(buf)) + if (evbuffer_get_length(buf) != 0) { evbuffer_add_printf(buf, "\n"); } diff --git a/libtransmission/variant-test.c b/libtransmission/variant-test.c index 125db0229..dfab86c41 100644 --- a/libtransmission/variant-test.c +++ b/libtransmission/variant-test.c @@ -38,7 +38,7 @@ static int testInt(void) err = tr_bencParseInt(buf, buf + 4, &end, &val); check_int_eq(0, err); check_int_eq(64, val); - check((buf + 4) == end); + check(buf + 4 == end); /* missing 'e' */ end = NULL; @@ -66,14 +66,14 @@ static int testInt(void) err = tr_bencParseInt(buf, buf + 4, &end, &val); check_int_eq(0, err); check_int_eq(-3, val); - check((buf + 4) == end); + check(buf + 4 == end); /* zero */ tr_snprintf((char*)buf, sizeof(buf), "i0e"); err = tr_bencParseInt(buf, buf + 4, &end, &val); check_int_eq(0, err); check_int_eq(0, val); - check((buf + 3) == end); + check(buf + 3 == end); /* no leading zeroes allowed */ val = 0; @@ -103,7 +103,7 @@ static int testStr(void) check_uint_eq(0, len); check(str == NULL); check(end == NULL); - check(!len); + check(len == 0); /* good string */ n = tr_snprintf((char*)buf, sizeof(buf), "4:boat"); @@ -122,14 +122,14 @@ static int testStr(void) check_uint_eq(0, len); check(str == NULL); check(end == NULL); - check(!len); + check(len == 0); /* empty string */ n = tr_snprintf((char*)buf, sizeof(buf), "0:"); err = tr_bencParseStr(buf, buf + n, &end, &str, &len); check_int_eq(0, err); check_uint_eq(0, len); - check(!*str); + check(*str == '\0'); check(end == buf + 2); str = NULL; end = NULL; @@ -162,11 +162,11 @@ static int testString(char const* str, bool isGood) if (!isGood) { - check(err); + check(err != 0); } else { - check(!err); + check(err == 0); #if 0 fprintf(stderr, "in: [%s]\n", str); fprintf(stderr, "out:\n%s", tr_variantToStr(&val, TR_VARIANT_FMT_JSON, NULL)); @@ -196,7 +196,7 @@ static int testParse(void) tr_snprintf((char*)buf, sizeof(buf), "i64e"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(!err); + check(err == 0); check(tr_variantGetInt(&val, &i)); check_int_eq(64, i); check(end == buf + 4); @@ -204,7 +204,7 @@ static int testParse(void) tr_snprintf((char*)buf, sizeof(buf), "li64ei32ei16ee"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(!err); + check(err == 0); check(end == buf + strlen((char*)buf)); check(val.val.l.count == 3); check(tr_variantGetInt(&val.val.l.vals[0], &i)); @@ -221,60 +221,60 @@ static int testParse(void) end = NULL; tr_snprintf((char*)buf, sizeof(buf), "lllee"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(err); + check(err != 0); check(end == NULL); end = NULL; tr_snprintf((char*)buf, sizeof(buf), "le"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(!err); + check(err == 0); check(end == buf + 2); saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len); check_streq("le", saved); tr_free(saved); tr_variantFree(&val); - if ((err = testString("llleee", true))) + if ((err = testString("llleee", true)) != 0) { return err; } - if ((err = testString("d3:cow3:moo4:spam4:eggse", true))) + if ((err = testString("d3:cow3:moo4:spam4:eggse", true)) != 0) { return err; } - if ((err = testString("d4:spaml1:a1:bee", true))) + if ((err = testString("d4:spaml1:a1:bee", true)) != 0) { return err; } - if ((err = testString("d5:greenli1ei2ei3ee4:spamd1:ai123e3:keyi214eee", true))) + if ((err = testString("d5:greenli1ei2ei3ee4:spamd1:ai123e3:keyi214eee", true)) != 0) { return err; } - if ((err = testString("d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee", true))) + if ((err = testString("d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee", true)) != 0) { return err; } - if ((err = testString("d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e", true))) + if ((err = testString("d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e", true)) != 0) { return err; } - if ((err = testString("d1:ai0e1:be", false))) /* odd number of children */ + if ((err = testString("d1:ai0e1:be", false)) != 0) /* odd number of children */ { return err; } - if ((err = testString("", false))) + if ((err = testString("", false)) != 0) { return err; } - if ((err = testString(" ", false))) + if ((err = testString(" ", false)) != 0) { return err; } @@ -285,10 +285,10 @@ static int testParse(void) end = NULL; tr_snprintf((char*)buf, sizeof(buf), "lld1:bi32e1:ai64eeee"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(!err); + check(err == 0); check(end == buf + strlen((char const*)buf)); - check((child = tr_variantListChild(&val, 0))); - check((child2 = tr_variantListChild(child, 0))); + check((child = tr_variantListChild(&val, 0)) != NULL); + check((child2 = tr_variantListChild(child, 0)) != NULL); saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len); check_streq("lld1:ai64e1:bi32eeee", saved); tr_free(saved); @@ -298,7 +298,7 @@ static int testParse(void) end = NULL; tr_snprintf((char*)buf, sizeof(buf), "leee"); err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end); - check(!err); + check(err == 0); check(end == buf + 2); saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len); check_streq("le", saved); @@ -309,13 +309,13 @@ static int testParse(void) end = NULL; tr_snprintf((char*)buf, sizeof(buf), "l1:a1:b1:c"); err = tr_variantFromBencFull(&val, buf, strlen(buf), NULL, &end); - check(err); + check(err != 0); /* incomplete string */ end = NULL; tr_snprintf((char*)buf, sizeof(buf), "1:"); err = tr_variantFromBencFull(&val, buf, strlen(buf), NULL, &end); - check(err); + check(err != 0); return 0; } @@ -324,7 +324,7 @@ static void stripWhitespace(char* in) { char* out; - for (out = in; in && *in; ++in) + for (out = in; in != NULL && *in != '\0'; ++in) { if (!isspace(*in)) { @@ -365,7 +365,7 @@ static int testJSON(void) benc_str = "i6e"; expected = "6"; - if ((val = testJSONSnippet(benc_str, expected))) + if ((val = testJSONSnippet(benc_str, expected)) != 0) { return val; } @@ -373,7 +373,7 @@ static int testJSON(void) benc_str = "d5:helloi1e5:worldi2ee"; expected = "{\"hello\":1,\"world\":2}"; - if ((val = testJSONSnippet(benc_str, expected))) + if ((val = testJSONSnippet(benc_str, expected)) != 0) { return val; } @@ -381,7 +381,7 @@ static int testJSON(void) benc_str = "d5:helloi1e5:worldi2e3:fooli1ei2ei3eee"; expected = "{\"foo\":[1,2,3],\"hello\":1,\"world\":2}"; - if ((val = testJSONSnippet(benc_str, expected))) + if ((val = testJSONSnippet(benc_str, expected)) != 0) { return val; } @@ -389,7 +389,7 @@ static int testJSON(void) benc_str = "d5:helloi1e5:worldi2e3:fooli1ei2ei3ed1:ai0eeee"; expected = "{\"foo\":[1,2,3,{\"a\":0}],\"hello\":1,\"world\":2}"; - if ((val = testJSONSnippet(benc_str, expected))) + if ((val = testJSONSnippet(benc_str, expected)) != 0) { return val; } @@ -397,7 +397,7 @@ static int testJSON(void) benc_str = "d4:argsd6:statusle7:status2lee6:result7:successe"; expected = "{\"args\":{\"status\":[],\"status2\":[]},\"result\":\"success\"}"; - if ((val = testJSONSnippet(benc_str, expected))) + if ((val = testJSONSnippet(benc_str, expected)) != 0) { return val; } @@ -488,7 +488,7 @@ static int testStackSmash(void) in[depth * 2] = '\0'; err = tr_variantFromBencFull(&val, in, depth * 2, NULL, &end); check_int_eq(0, err); - check(end == in + (depth * 2)); + check(end == in + depth * 2); saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len); check_streq((char*)in, saved); tr_free(in); @@ -523,13 +523,13 @@ static int testBool(void) check(tr_variantDictFindBool(&top, key4, &boolVal)); check(boolVal); check(tr_variantDictFindInt(&top, key1, &intVal)); - check(!intVal); + check(intVal == 0); check(tr_variantDictFindInt(&top, key2, &intVal)); - check(!intVal); + check(intVal == 0); check(tr_variantDictFindInt(&top, key3, &intVal)); - check(intVal); + check(intVal != 0); check(tr_variantDictFindInt(&top, key4, &intVal)); - check(intVal); + check(intVal != 0); tr_variantFree(&top); return 0; @@ -561,7 +561,7 @@ static int testParse2(void) benc = tr_variantToStr(&top, TR_VARIANT_FMT_BENC, &len); check_streq("d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-int" "i1234ee", benc); - check(!tr_variantFromBencFull(&top2, benc, len, NULL, &end)); + check(tr_variantFromBencFull(&top2, benc, len, NULL, &end) == 0); check(end == benc + len); check(tr_variantIsDict(&top2)); check(tr_variantDictFindInt(&top, key_int, &intVal)); diff --git a/libtransmission/variant.c b/libtransmission/variant.c index 23b8d47d0..7cb241978 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -265,7 +265,7 @@ tr_variant* tr_variantListChild(tr_variant* v, size_t i) { tr_variant* ret = NULL; - if (tr_variantIsList(v) && (i < v->val.l.count)) + if (tr_variantIsList(v) && i < v->val.l.count) { ret = v->val.l.vals + i; } @@ -277,7 +277,7 @@ bool tr_variantListRemove(tr_variant* list, size_t i) { bool removed = false; - if (tr_variantIsList(list) && (i < list->val.l.count)) + if (tr_variantIsList(list) && i < list->val.l.count) { removed = true; tr_variantFree(&list->val.l.vals[i]); @@ -291,17 +291,17 @@ bool tr_variantGetInt(tr_variant const* v, int64_t* setme) { bool success = false; - if (!success && ((success = tr_variantIsInt(v)))) + if (!success && (success = tr_variantIsInt(v))) { - if (setme) + if (setme != NULL) { *setme = v->val.i; } } - if (!success && ((success = tr_variantIsBool(v)))) + if (!success && (success = tr_variantIsBool(v))) { - if (setme) + if (setme != NULL) { *setme = v->val.b ? 1 : 0; } @@ -352,7 +352,7 @@ bool tr_variantGetBool(tr_variant const* v, bool* setme) if (!success && tr_variantIsInt(v)) { - if ((success = (v->val.i == 0 || v->val.i == 1))) + if ((success = v->val.i == 0 || v->val.i == 1)) { *setme = v->val.i != 0; } @@ -360,7 +360,7 @@ bool tr_variantGetBool(tr_variant const* v, bool* setme) if (!success && tr_variantGetStr(v, &str, NULL)) { - if ((success = (strcmp(str, "true") == 0 || strcmp(str, "false") == 0))) + if ((success = strcmp(str, "true") == 0 || strcmp(str, "false") == 0)) { *setme = strcmp(str, "true") == 0; } @@ -373,12 +373,12 @@ bool tr_variantGetReal(tr_variant const* v, double* setme) { bool success = false; - if (!success && ((success = tr_variantIsReal(v)))) + if (!success && (success = tr_variantIsReal(v))) { *setme = v->val.d; } - if (!success && ((success = tr_variantIsInt(v)))) + if (!success && (success = tr_variantIsInt(v))) { *setme = v->val.i; } @@ -394,7 +394,7 @@ bool tr_variantGetReal(tr_variant const* v, double* setme) d = strtod(getStr(v), &endptr); restore_locale(&locale_ctx); - if ((success = (getStr(v) != endptr) && !*endptr)) + if ((success = getStr(v) != endptr && *endptr == '\0')) { *setme = d; } @@ -498,7 +498,7 @@ static void containerReserve(tr_variant* v, size_t count) if (needed > v->val.l.alloc) { /* scale the alloc size in powers-of-2 */ - size_t n = v->val.l.alloc ? v->val.l.alloc : 8; + size_t n = v->val.l.alloc != 0 ? v->val.l.alloc : 8; while (n < needed) { @@ -617,7 +617,7 @@ static tr_variant* dictFindOrAdd(tr_variant* dict, tr_quark const key, int type) tr_variant* child; /* see if it already exists, and if so, try to reuse it */ - if ((child = tr_variantDictFind(dict, key))) + if ((child = tr_variantDictFind(dict, key)) != NULL) { if (!tr_variantIsType(child, type)) { @@ -825,7 +825,7 @@ void tr_variantWalk(tr_variant const* v, struct VariantWalkFuncs const* walkFunc v = node->v; node->isVisited = true; } - else if (tr_variantIsContainer(node->v) && (node->childIndex < node->v->val.l.count)) + else if (tr_variantIsContainer(node->v) && node->childIndex < node->v->val.l.count) { int const index = node->childIndex++; v = node->v->val.l.vals + index; @@ -849,7 +849,7 @@ void tr_variantWalk(tr_variant const* v, struct VariantWalkFuncs const* walkFunc continue; } - if (v) + if (v != NULL) { switch (v->type) { @@ -962,7 +962,7 @@ static void tr_variantListCopy(tr_variant* target, tr_variant const* src) int i = 0; tr_variant const* val; - while ((val = tr_variantListChild((tr_variant*)src, i++))) + while ((val = tr_variantListChild((tr_variant*)src, i++)) != NULL) { if (tr_variantIsBool(val)) { @@ -1015,7 +1015,7 @@ bool tr_variantDictChild(tr_variant* dict, size_t n, tr_quark* key, tr_variant** assert(tr_variantIsDict(dict)); - if (tr_variantIsDict(dict) && (n < dict->val.l.count)) + if (tr_variantIsDict(dict) && n < dict->val.l.count) { *key = dict->val.l.vals[n].key; *val = dict->val.l.vals + n; diff --git a/libtransmission/variant.h b/libtransmission/variant.h index ffa1f0fad..0f552545e 100644 --- a/libtransmission/variant.h +++ b/libtransmission/variant.h @@ -150,7 +150,7 @@ static inline int tr_variantFromJson(tr_variant* setme, void const* buf, size_t static inline bool tr_variantIsType(tr_variant const* b, int type) { - return (b != NULL) && (b->type == type); + return b != NULL && b->type == type; } /*** @@ -159,7 +159,7 @@ static inline bool tr_variantIsType(tr_variant const* b, int type) static inline bool tr_variantIsString(tr_variant const* b) { - return (b != NULL) && (b->type == TR_VARIANT_TYPE_STR); + return b != NULL && b->type == TR_VARIANT_TYPE_STR; } bool tr_variantGetStr(tr_variant const* variant, char const** setme_str, size_t* setme_len); @@ -176,7 +176,7 @@ bool tr_variantGetRaw(tr_variant const* variant, uint8_t const** raw_setme, size static inline bool tr_variantIsReal(tr_variant const* v) { - return (v != NULL) && (v->type == TR_VARIANT_TYPE_REAL); + return v != NULL && v->type == TR_VARIANT_TYPE_REAL; } void tr_variantInitReal(tr_variant* initme, double value); @@ -188,7 +188,7 @@ bool tr_variantGetReal(tr_variant const* variant, double* value_setme); static inline bool tr_variantIsBool(tr_variant const* v) { - return (v != NULL) && (v->type == TR_VARIANT_TYPE_BOOL); + return v != NULL && v->type == TR_VARIANT_TYPE_BOOL; } void tr_variantInitBool(tr_variant* initme, bool value); @@ -200,7 +200,7 @@ bool tr_variantGetBool(tr_variant const* variant, bool* setme); static inline bool tr_variantIsInt(tr_variant const* v) { - return (v != NULL) && (v->type == TR_VARIANT_TYPE_INT); + return v != NULL && v->type == TR_VARIANT_TYPE_INT; } void tr_variantInitInt(tr_variant* variant, int64_t value); @@ -212,7 +212,7 @@ bool tr_variantGetInt(tr_variant const* val, int64_t* setme); static inline bool tr_variantIsList(tr_variant const* v) { - return (v != NULL) && (v->type == TR_VARIANT_TYPE_LIST); + return v != NULL && v->type == TR_VARIANT_TYPE_LIST; } void tr_variantInitList(tr_variant* list, size_t reserve_count); @@ -238,7 +238,7 @@ size_t tr_variantListSize(tr_variant const* list); static inline bool tr_variantIsDict(tr_variant const* v) { - return (v != NULL) && (v->type == TR_VARIANT_TYPE_DICT); + return v != NULL && v->type == TR_VARIANT_TYPE_DICT; } void tr_variantInitDict(tr_variant* initme, size_t reserve_count); diff --git a/libtransmission/verify.c b/libtransmission/verify.c index 279d2f42c..854b65940 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -60,7 +60,7 @@ static bool verifyTorrent(tr_torrent* tor, bool* stopFlag) tr_logAddTorDbg(tor, "%s", "verifying torrent..."); tr_torrentSetChecked(tor, 0); - while (!*stopFlag && (pieceIndex < tor->info.pieceCount)) + while (!*stopFlag && pieceIndex < tor->info.pieceCount) { uint64_t leftInPiece; uint64_t bytesThisPass; @@ -207,13 +207,13 @@ static void verifyThreadFunc(void* unused UNUSED) { for (;;) { - int changed = 0; + bool changed = false; tr_torrent* tor; struct verify_node* node; tr_lockLock(getVerifyLock()); stopCurrent = false; - node = (struct verify_node*)verifyList ? verifyList->data : NULL; + node = verifyList != NULL ? verifyList->data : NULL; if (node == NULL) { @@ -238,7 +238,7 @@ static void verifyThreadFunc(void* unused UNUSED) tr_torrentSetDirty(tor); } - if (currentNode.callback_func) + if (currentNode.callback_func != NULL) { (*currentNode.callback_func)(tor, stopCurrent, currentNode.callback_data); } diff --git a/libtransmission/web.c b/libtransmission/web.c index b6cf1120b..01d0f6ade 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -90,7 +90,7 @@ struct tr_web_task static void task_free(struct tr_web_task* task) { - if (task->freebuf) + if (task->freebuf != NULL) { evbuffer_free(task->freebuf); } @@ -132,7 +132,7 @@ static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* vtask) { tr_torrent* tor = tr_torrentFindFromId(task->session, task->torrentId); - if (tor && !tr_bandwidthClamp(&tor->bandwidth, TR_DOWN, nmemb)) + if (tor != NULL && tr_bandwidthClamp(&tor->bandwidth, TR_DOWN, nmemb) == 0) { tr_list_append(&paused_easy_handles, task->curl_easy); return CURL_WRITEFUNC_PAUSE; @@ -172,7 +172,7 @@ static long getTimeoutFromURL(struct tr_web_task const* task) long timeout; tr_session const* session = task->session; - if (!session || session->isClosed) + if (session == NULL || session->isClosed) { timeout = 20L; } @@ -229,11 +229,11 @@ static CURL* createEasy(tr_session* s, struct tr_web* web, struct tr_web_task* t curl_easy_setopt(e, CURLOPT_WRITEDATA, task); curl_easy_setopt(e, CURLOPT_WRITEFUNCTION, writeFunc); - if (((addr = tr_sessionGetPublicAddress(s, TR_AF_INET, &is_default_value))) && !is_default_value) + if ((addr = tr_sessionGetPublicAddress(s, TR_AF_INET, &is_default_value)) != NULL && !is_default_value) { curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr)); } - else if (((addr = tr_sessionGetPublicAddress(s, TR_AF_INET6, &is_default_value))) && !is_default_value) + else if ((addr = tr_sessionGetPublicAddress(s, TR_AF_INET6, &is_default_value)) != NULL && !is_default_value) { curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr)); } @@ -307,8 +307,8 @@ static struct tr_web_task* tr_webRunImpl(tr_session* session, int torrentId, cha task->cookies = tr_strdup(cookies); task->done_func = done_func; task->done_func_user_data = done_func_user_data; - task->response = buffer ? buffer : evbuffer_new(); - task->freebuf = buffer ? NULL : task->response; + task->response = buffer != NULL ? buffer : evbuffer_new(); + task->freebuf = buffer != NULL ? NULL : task->response; tr_lockLock(session->web->taskLock); task->next = session->web->tasks; @@ -350,13 +350,13 @@ static void tr_select(int nfds, fd_set* r_fd_set, fd_set* w_fd_set, fd_set* c_fd (void)nfds; - if (!r_fd_set->fd_count && !w_fd_set->fd_count && !c_fd_set->fd_count) + if (r_fd_set->fd_count == 0 && w_fd_set->fd_count == 0 && c_fd_set->fd_count == 0) { long int const msec = t->tv_sec * 1000 + t->tv_usec / 1000; tr_wait_msec(msec); } - else if (select(0, r_fd_set->fd_count ? r_fd_set : NULL, w_fd_set->fd_count ? w_fd_set : NULL, - c_fd_set->fd_count ? c_fd_set : NULL, t) < 0) + else if (select(0, r_fd_set->fd_count != 0 ? r_fd_set : NULL, w_fd_set->fd_count != 0 ? w_fd_set : NULL, + c_fd_set->fd_count != 0 ? c_fd_set : NULL, t) < 0) { char errstr[512]; int const e = EVUTIL_SOCKET_ERROR(); @@ -382,7 +382,7 @@ static void tr_webThreadFunc(void* vsession) /* try to enable ssl for https support; but if that fails, * try a plain vanilla init */ - if (curl_global_init(CURL_GLOBAL_SSL)) + if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) { curl_global_init(0); } @@ -427,7 +427,7 @@ static void tr_webThreadFunc(void* vsession) break; } - if ((web->close_mode == TR_WEB_CLOSE_WHEN_IDLE) && (web->tasks == NULL)) + if (web->close_mode == TR_WEB_CLOSE_WHEN_IDLE && web->tasks == NULL) { break; } @@ -461,7 +461,7 @@ static void tr_webThreadFunc(void* vsession) tmp = paused_easy_handles; paused_easy_handles = NULL; - while ((handle = tr_list_pop_front(&tmp))) + while ((handle = tr_list_pop_front(&tmp)) != NULL) { curl_easy_pause(handle, CURLPAUSE_CONT); } @@ -513,9 +513,9 @@ static void tr_webThreadFunc(void* vsession) while (mcode == CURLM_CALL_MULTI_PERFORM); /* pump completed tasks from the multi */ - while ((msg = curl_multi_info_read(multi, &unused))) + while ((msg = curl_multi_info_read(multi, &unused)) != NULL) { - if ((msg->msg == CURLMSG_DONE) && (msg->easy_handle != NULL)) + if (msg->msg == CURLMSG_DONE && msg->easy_handle != NULL) { double total_time; struct tr_web_task* task; @@ -527,7 +527,7 @@ static void tr_webThreadFunc(void* vsession) curl_easy_getinfo(e, CURLINFO_REQUEST_SIZE, &req_bytes_sent); curl_easy_getinfo(e, CURLINFO_TOTAL_TIME, &total_time); task->did_connect = task->code > 0 || req_bytes_sent > 0; - task->did_timeout = !task->code && (total_time >= task->timeout_secs); + task->did_timeout = task->code == 0 && total_time >= task->timeout_secs; curl_multi_remove_handle(multi, e); tr_list_remove_data(&paused_easy_handles, e); curl_easy_cleanup(e); @@ -729,8 +729,8 @@ void tr_http_escape(struct evbuffer* out, char const* str, size_t len, bool esca for (char const* end = str + len; str != end; ++str) { - if ((*str == ',') || (*str == '-') || (*str == '.') || (('0' <= *str) && (*str <= '9')) || - (('A' <= *str) && (*str <= 'Z')) || (('a' <= *str) && (*str <= 'z')) || ((*str == '/') && (!escape_slashes))) + if (*str == ',' || *str == '-' || *str == '.' || ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'Z') || + ('a' <= *str && *str <= 'z') || (*str == '/' && !escape_slashes)) { evbuffer_add_printf(out, "%c", *str); } diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index 67726894a..cfbe787c8 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -196,13 +196,13 @@ static void connection_succeeded(void* vdata) struct connection_succeeded_data* data = vdata; struct tr_webseed* w = data->webseed; - if (++w->active_transfers >= w->retry_challenge && w->retry_challenge) + if (++w->active_transfers >= w->retry_challenge && w->retry_challenge != 0) { /* the server seems to be accepting more connections now */ w->consecutive_failures = w->retry_tickcount = w->retry_challenge = 0; } - if (data->real_url && (tor = tr_torrentFindFromId(w->session, w->torrent_id))) + if (data->real_url != NULL && (tor = tr_torrentFindFromId(w->session, w->torrent_id)) != NULL) { uint64_t file_offset; tr_file_index_t file_index; @@ -229,7 +229,7 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con tr_sessionLock(session); - if (!task->dead && (n_added > 0)) + if (!task->dead && n_added > 0) { uint32_t len; struct tr_webseed* w = task->webseed; @@ -238,7 +238,7 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con fire_client_got_piece_data(w, n_added); len = evbuffer_get_length(buf); - if (!task->response_code) + if (task->response_code == 0) { tr_webGetTaskInfo(task->web_task, TR_WEB_GET_CODE, &task->response_code); @@ -262,7 +262,7 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con } } - if ((task->response_code == 206) && (len >= task->block_size)) + if (task->response_code == 206 && len >= task->block_size) { /* once we've got at least one full block, save it */ @@ -318,7 +318,7 @@ static void on_idle(tr_webseed* w) w->retry_challenge = running_tasks + w->idle_connections + 1; } - if (tor && tor->isRunning && !tr_torrentIsSeed(tor) && (want > 0)) + if (tor != NULL && tor->isRunning && !tr_torrentIsSeed(tor) && want > 0) { int i; int got = 0; @@ -390,16 +390,16 @@ static void web_response_func(tr_session* session, bool did_connect UNUSED, bool { tr_block_index_t const blocks_remain = (t->length + tor->blockSize - 1) / tor->blockSize - t->blocks_done; - if (blocks_remain) + if (blocks_remain != 0) { fire_client_got_rejs(tor, w, t->block + t->blocks_done, blocks_remain); } - if (t->blocks_done) + if (t->blocks_done != 0) { ++w->idle_connections; } - else if (++w->consecutive_failures >= MAX_CONSECUTIVE_FAILURES && !w->retry_tickcount) + else if (++w->consecutive_failures >= MAX_CONSECUTIVE_FAILURES && w->retry_tickcount == 0) { /* now wait a while until retrying to establish a connection */ ++w->retry_tickcount; @@ -423,7 +423,7 @@ static void web_response_func(tr_session* session, bool did_connect UNUSED, bool } else { - if (buf_len && !tr_torrentPieceIsComplete(tor, t->piece_index)) + if (buf_len != 0 && !tr_torrentPieceIsComplete(tor, t->piece_index)) { /* on_content_changed() will not write a block if it is smaller than the torrent's block size, i.e. the torrent's very last block */ @@ -451,7 +451,7 @@ static struct evbuffer* make_url(tr_webseed* w, tr_file const* file) evbuffer_add(buf, w->base_url, w->base_url_len); /* if url ends with a '/', add the torrent name */ - if (w->base_url[w->base_url_len - 1] == '/' && file->name) + if (w->base_url[w->base_url_len - 1] == '/' && file->name != NULL) { tr_http_escape(buf, file->name, strlen(file->name), false); } @@ -504,7 +504,7 @@ static void webseed_timer_func(evutil_socket_t foo UNUSED, short bar UNUSED, voi { tr_webseed* w = vw; - if (w->retry_tickcount) + if (w->retry_tickcount != 0) { ++w->retry_tickcount; } diff --git a/qt/AddData.cc b/qt/AddData.cc index 5bb9174e1..765fd6713 100644 --- a/qt/AddData.cc +++ b/qt/AddData.cc @@ -47,7 +47,7 @@ int AddData::set(QString const& key) size_t len; void* raw = tr_base64_decode(key.toUtf8().constData(), key.toUtf8().size(), &len); - if (raw) + if (raw != nullptr) { metainfo.append(static_cast