From fbd8d4c79fc491cd63b1e7e1d4f5d28b29bb3e15 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 30 Apr 2017 19:30:03 +0300 Subject: [PATCH] Fix a number of other style inconsistencies met along the way --- daemon/remote.c | 4 ++-- gtk/tr-core.c | 2 +- gtk/util.c | 4 ++-- libtransmission/announcer-udp.c | 4 ++-- libtransmission/announcer.c | 10 +++++----- libtransmission/bandwidth.c | 2 +- libtransmission/bitfield.c | 10 +++++----- libtransmission/completion.c | 2 +- libtransmission/handshake.c | 2 +- libtransmission/history.h | 3 ++- libtransmission/log.c | 2 +- libtransmission/magnet.c | 2 +- libtransmission/peer-io.c | 2 +- libtransmission/peer-mgr.c | 8 ++++---- libtransmission/peer-msgs.c | 8 ++++---- libtransmission/platform-quota.c | 2 ++ libtransmission/ptrarray.c | 2 +- libtransmission/resume.c | 2 +- libtransmission/rpc-server.c | 5 ++--- libtransmission/rpcimpl.c | 4 ++-- libtransmission/session-id.c | 2 -- libtransmission/session.c | 1 + libtransmission/torrent.c | 31 +++++++++++++++---------------- libtransmission/trevent.c | 2 +- libtransmission/utils.c | 14 +++++++------- libtransmission/utils.h | 8 ++++---- libtransmission/variant-json.c | 6 +++--- libtransmission/variant.c | 2 +- libtransmission/web.c | 2 +- libtransmission/webseed.c | 8 ++++---- qt/DetailsDialog.cc | 4 +++- qt/FilterBar.cc | 4 ++-- qt/MainWindow.cc | 5 +++++ qt/TrackerDelegate.cc | 2 +- utils/edit.c | 4 ++-- 35 files changed, 91 insertions(+), 84 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 16b06a7ff..4df6bb6e6 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -827,7 +827,7 @@ static char* getStatusString(tr_variant* t, char* buf, size_t buflen) if (tr_variantDictFindReal(t, TR_KEY_recheckProgress, &percent)) { - tr_snprintf(buf, buflen, "%s (%.0f%%)", str, floor(percent * 100.0)); + tr_snprintf(buf, buflen, "%s (%.0f%%)", str, (floor)(percent * 100.0)); } else { @@ -1252,7 +1252,7 @@ static void printFileList(tr_variant* top) break; } - printf("%3d: %3.0f%% %-8s %-3s %9s %s\n", j, floor(100.0 * percent), pristr, wanted ? "Yes" : "No", + printf("%3d: %3.0f%% %-8s %-3s %9s %s\n", j, (floor)(100.0 * percent), pristr, wanted ? "Yes" : "No", sizestr, filename); } } diff --git a/gtk/tr-core.c b/gtk/tr-core.c index b504bf41a..4b30a01f5 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -1778,7 +1778,7 @@ static void core_read_rpc_response(tr_session* session UNUSED, tr_variant* respo gdk_threads_add_idle(core_read_rpc_response_idle, response_copy); } -static void core_send_rpc_request(TrCore* core, tr_variant const* request, int tag, server_response_func* response_func, +static void core_send_rpc_request(TrCore* core, tr_variant const* request, int tag, server_response_func response_func, void* response_func_user_data) { tr_session* session = gtr_core_session(core); diff --git a/gtk/util.c b/gtk/util.c index 421ea8f98..fb9b70bba 100644 --- a/gtk/util.c +++ b/gtk/util.c @@ -272,7 +272,7 @@ void gtr_add_torrent_error_dialog(GtkWidget* child, int err, tr_torrent* duplica g_free(secondary); } -typedef void (PopupFunc)(GtkWidget*, GdkEventButton*); +typedef void (* PopupFunc)(GtkWidget*, GdkEventButton*); /* pop up the context menu if a user right-clicks. if the row they right-click on isn't selected, select it. */ @@ -299,7 +299,7 @@ gboolean on_tree_view_button_pressed(GtkWidget* view, GdkEventButton* event, gpo if (func != NULL) { - ((PopupFunc*)func)(view, event); + (*(PopupFunc)func)(view, event); } return TRUE; diff --git a/libtransmission/announcer-udp.c b/libtransmission/announcer-udp.c index c24bc50f7..026733fce 100644 --- a/libtransmission/announcer-udp.c +++ b/libtransmission/announcer-udp.c @@ -531,7 +531,7 @@ static void tau_tracker_on_dns(int errcode, struct evutil_addrinfo* addr, void* { dbgmsg(tracker->key, "DNS lookup succeeded"); tracker->addr = addr; - tracker->addr_expiration_time = tr_time() + (60 * 60); /* one hour */ + tracker->addr_expiration_time = tr_time() + 60 * 60; /* one hour */ tau_tracker_upkeep(tracker); } } @@ -940,7 +940,7 @@ bool tau_handle_message(tr_session* session, uint8_t const* msg, size_t msglen) tau = session->announcer_udp; transaction_id = evbuffer_read_ntoh_32(buf); - /*fprintf(stderr, "UDP got a transaction_id %u...\n", transaction_id);*/ + /* fprintf(stderr, "UDP got a transaction_id %u...\n", transaction_id); */ for (i = 0, n = tr_ptrArraySize(&tau->trackers); i < n; ++i) { int j, jn; diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index fbed5663d..bb88ab9a4 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -1000,19 +1000,19 @@ static int getRetryInterval(tr_tracker const* t) return 20; case 2: - return tr_rand_int_weak(60) + (60 * 5); + return tr_rand_int_weak(60) + 60 * 5; case 3: - return tr_rand_int_weak(60) + (60 * 15); + return tr_rand_int_weak(60) + 60 * 15; case 4: - return tr_rand_int_weak(60) + (60 * 30); + return tr_rand_int_weak(60) + 60 * 30; case 5: - return tr_rand_int_weak(60) + (60 * 60); + return tr_rand_int_weak(60) + 60 * 60; default: - return tr_rand_int_weak(60) + (60 * 120); + return tr_rand_int_weak(60) + 60 * 120; } } diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index 61a096c99..4ac089019 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -64,7 +64,7 @@ static unsigned int getSpeed_Bps(struct bratecontrol const* r, unsigned int inte } } - rvolatile->cache_val = (unsigned int)((bytes * 1000u) / interval_msec); + rvolatile->cache_val = (unsigned int)(bytes * 1000u / interval_msec); rvolatile->cache_time = now; } diff --git a/libtransmission/bitfield.c b/libtransmission/bitfield.c index 92cf7a583..e480e8b1d 100644 --- a/libtransmission/bitfield.c +++ b/libtransmission/bitfield.c @@ -373,7 +373,7 @@ void tr_bitfieldSetRaw(tr_bitfield* b, void const* bits, size_t byte_count, bool if (excess_bit_count) { - b->bits[b->alloc_count - 1] &= ((0xff) << excess_bit_count); + b->bits[b->alloc_count - 1] &= 0xff << excess_bit_count; } } @@ -404,7 +404,7 @@ void tr_bitfieldAdd(tr_bitfield* b, size_t nth) { if (!tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth)) { - b->bits[nth >> 3u] |= (0x80 >> (nth & 7u)); + b->bits[nth >> 3u] |= 0x80 >> (nth & 7u); tr_bitfieldIncTrueCount(b, 1); } } @@ -440,7 +440,7 @@ void tr_bitfieldAddRange(tr_bitfield* b, size_t begin, size_t end) if (sb == eb) { - b->bits[sb] |= (sm & em); + b->bits[sb] |= sm & em; } else { @@ -462,7 +462,7 @@ void tr_bitfieldRem(tr_bitfield* b, size_t nth) if (tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth)) { - b->bits[nth >> 3u] &= (0xff7f >> (nth & 7u)); + b->bits[nth >> 3u] &= 0xff7f >> (nth & 7u); tr_bitfieldDecTrueCount(b, 1); } } @@ -498,7 +498,7 @@ void tr_bitfieldRemRange(tr_bitfield* b, size_t begin, size_t end) if (sb == eb) { - b->bits[sb] &= (sm | em); + b->bits[sb] &= sm | em; } else { diff --git a/libtransmission/completion.c b/libtransmission/completion.c index 159afbd07..a1a55dbd6 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -188,7 +188,7 @@ uint64_t tr_cpSizeWhenDone(tr_completion const* ccp) if (l == cp->tor->blockCount - 1 && tr_bitfieldHas(&cp->blockBitfield, l)) { - n -= (cp->tor->blockSize - cp->tor->lastBlockSize); + n -= cp->tor->blockSize - cp->tor->lastBlockSize; } } diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index dc0c7a66a..4f1673733 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -788,7 +788,7 @@ static ReadState readYa(tr_handshake* handshake, struct evbuffer* inbuf) static ReadState readPadA(tr_handshake* handshake, struct evbuffer* inbuf) { - /* resynchronizing on HASH('req1',S) */ + /* resynchronizing on HASH('req1', S) */ struct evbuffer_ptr ptr = evbuffer_search(inbuf, (char const*)handshake->myReq1, SHA_DIGEST_LENGTH, NULL); if (ptr.pos != -1) /* match */ diff --git a/libtransmission/history.h b/libtransmission/history.h index c19ab13ef..5a66bd47d 100644 --- a/libtransmission/history.h +++ b/libtransmission/history.h @@ -36,7 +36,8 @@ typedef struct tr_recentHistory { unsigned int n; time_t date; - } slices[TR_RECENT_HISTORY_PERIOD_SEC]; + } + slices[TR_RECENT_HISTORY_PERIOD_SEC]; } tr_recentHistory; diff --git a/libtransmission/log.c b/libtransmission/log.c index bfea61f36..29c509642 100644 --- a/libtransmission/log.c +++ b/libtransmission/log.c @@ -164,7 +164,7 @@ bool tr_logGetDeepEnabled(void) if (deepLoggingIsActive < 0) { - deepLoggingIsActive = IsDebuggerPresent() || (tr_logGetFile() != TR_BAD_SYS_FILE); + deepLoggingIsActive = IsDebuggerPresent() || tr_logGetFile() != TR_BAD_SYS_FILE; } return deepLoggingIsActive != 0; diff --git a/libtransmission/magnet.c b/libtransmission/magnet.c index 39cceac07..9537b8ab3 100644 --- a/libtransmission/magnet.c +++ b/libtransmission/magnet.c @@ -89,7 +89,7 @@ static void base32_to_sha1(uint8_t* out, char const* in, size_t const inlen) else { index = (index + 5) % 8; - out[offset] |= (digit >> index); + out[offset] |= digit >> index; offset++; if (offset >= outlen) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 9df75042d..86ee43b16 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -1024,7 +1024,7 @@ void tr_peerIoSetPeersId(tr_peerIo* io, uint8_t const* peer_id) } else { - memset(io->peerId, 0, 20); + memset(io->peerId, '\0', 20); } } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 98ac95fad..f85ded87b 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1480,7 +1480,7 @@ void tr_peerMgrGetNextRequests(tr_torrent* tor, tr_peer* peer, int numwant, tr_b } /* In most cases we've just changed the weights of a small number of pieces. - * So rather than qsort ()ing the entire array, it's faster to apply an + * So rather than qsort()ing the entire array, it's faster to apply an * adaptive insertion sort algorithm. */ if (got > 0) { @@ -3467,14 +3467,14 @@ static bool shouldPeerBeClosed(tr_swarm const* s, tr_peer const* peer, int peerC /* disconnect if it's been too long since piece data has been transferred. * this is on a sliding scale based on number of available peers... */ { - int const relaxStrictnessIfFewerThanN = (int)((getMaxPeerCount(tor) * 0.9) + 0.5); + int const relaxStrictnessIfFewerThanN = (int)(getMaxPeerCount(tor) * 0.9 + 0.5); /* if we have >= relaxIfFewerThan, strictness is 100%. * if we have zero connections, strictness is 0% */ float const strictness = peerCount >= relaxStrictnessIfFewerThanN ? 1.0 : peerCount / (float)relaxStrictnessIfFewerThanN; int const lo = MIN_UPLOAD_IDLE_SECS; int const hi = MAX_UPLOAD_IDLE_SECS; - int const limit = hi - ((hi - lo) * strictness); + int const limit = hi - (hi - lo) * strictness; int const idleTime = now - MAX(atom->time, atom->piece_data_time); /* @@ -4160,7 +4160,7 @@ static bool torrentWasRecentlyStarted(tr_torrent const* tor) static inline uint64_t addValToKey(uint64_t value, int width, uint64_t addme) { - value = (value << (uint64_t)width); + value = value << (uint64_t)width; value |= addme; return value; } diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 649edc48a..2042382e1 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -859,8 +859,8 @@ static bool requestIsValid(tr_peerMsgs const* msgs, struct peer_request const* r void tr_peerMsgsCancel(tr_peerMsgs* msgs, tr_block_index_t block) { struct peer_request req; - // fprintf(stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", (size_t)block, - // msgs->peer); + // fprintf(stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", + // (size_t)block, msgs->peer); blockToReq(msgs->torrent, block, &req); protocolSendCancel(msgs, &req); } @@ -1516,7 +1516,7 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen uint32_t msglen = msgs->incoming.length; uint8_t const id = msgs->incoming.id; #ifndef NDEBUG - size_t const startBufLen = evbuffer_get_length(inbuf); + size_t const startBufLen = evbuffer_get_length(inbuf); #endif bool const fext = tr_peerIoSupportsFEXT(msgs->io); @@ -2316,7 +2316,7 @@ static inline void pexElementCb(void* vpex, void* userData) diffs->elements[diffs->elementCount++] = *pex; } -typedef void (tr_set_func)(void* element, void* userData); +typedef void (* tr_set_func)(void* element, void* userData); /** * @brief find the differences and commonalities in two sorted sets diff --git a/libtransmission/platform-quota.c b/libtransmission/platform-quota.c index aaa5889cd..d81cac0a1 100644 --- a/libtransmission/platform-quota.c +++ b/libtransmission/platform-quota.c @@ -324,6 +324,7 @@ static int64_t getquota(char const* device) if (quotactl(device, QCMD(Q_GETQUOTA, USRQUOTA), getuid(), (caddr_t)&dq) == 0) { + #elif defined(__sun) struct quotctl op; @@ -346,6 +347,7 @@ static int64_t getquota(char const* device) if (quotactl(QCMD(Q_GETQUOTA, USRQUOTA), device, getuid(), (caddr_t)&dq) == 0) { + #endif if (dq.dqb_bsoftlimit > 0) diff --git a/libtransmission/ptrarray.c b/libtransmission/ptrarray.c index 8e3e20118..5f4af685c 100644 --- a/libtransmission/ptrarray.c +++ b/libtransmission/ptrarray.c @@ -96,7 +96,7 @@ void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end) memmove(t->items + begin, t->items + end, sizeof(void*) * (t->n_items - end)); - t->n_items -= (end - begin); + t->n_items -= end - begin; } /** diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 4495e8d60..1af499a0c 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -72,7 +72,7 @@ static int addPeers(tr_torrent* tor, uint8_t const* buf, int buflen) for (i = 0; i < count && numAdded < MAX_REMEMBERED_PEERS; ++i) { tr_pex pex; - memcpy(&pex, buf + (i * sizeof(tr_pex)), sizeof(tr_pex)); + memcpy(&pex, buf + i * sizeof(tr_pex), sizeof(tr_pex)); if (tr_isPex(&pex)) { diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 00b3c08b7..3de52419b 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -142,7 +142,7 @@ static void extract_parts_from_multipart(struct evkeyvalq const* headers, struct size_t part_len; char const* part = delim + boundary_len; - inlen -= (part - in); + inlen -= part - in; in = part; delim = tr_memmem(in, inlen, boundary, boundary_len); @@ -366,8 +366,7 @@ static void add_response(struct evhttp_request* req, struct tr_rpc_server* serve #endif - evhttp_add_header(req->output_headers, - "Content-Encoding", "gzip"); + evhttp_add_header(req->output_headers, "Content-Encoding", "gzip"); } else { diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 2cdcb6ba5..a015b5bd2 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -38,7 +38,7 @@ #define RECENTLY_ACTIVE_SECONDS 60 -#define TR_N_ELEMENTS(ary)(sizeof(ary) / sizeof(*ary)) +#define TR_N_ELEMENTS(ary) (sizeof(ary) / sizeof(*ary)) #if 0 @@ -74,7 +74,7 @@ static tr_rpc_callback_status notify(tr_session* session, int type, tr_torrent* if (session->rpc_func != NULL) { - status = session->rpc_func(session, type, tor, session->rpc_func_user_data); + status = (*session->rpc_func)(session, type, tor, session->rpc_func_user_data); } return status; diff --git a/libtransmission/session-id.c b/libtransmission/session-id.c index 850e756dc..032febfd8 100644 --- a/libtransmission/session-id.c +++ b/libtransmission/session-id.c @@ -187,10 +187,8 @@ bool tr_session_id_is_local(char const* session_id) if (!tr_sys_file_lock(lock_file, TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_NB, &error)) { #ifndef _WIN32 - if (error->code == EWOULDBLOCK) #else - if (error->code == ERROR_LOCK_VIOLATION) #endif { diff --git a/libtransmission/session.c b/libtransmission/session.c index 2f8035e9f..b532bb52e 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -1446,6 +1446,7 @@ bool tr_sessionGetActiveSpeedLimit_Bps(tr_session const* session, tr_direction d return isLimited; } + bool tr_sessionGetActiveSpeedLimit_KBps(tr_session const* session, tr_direction dir, double* setme_KBps) { unsigned int Bps = 0; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index ade2c8c41..10d213199 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -207,7 +207,7 @@ static int peerIdTTL(tr_torrent const* tor) } else { - ttl = (int)difftime(tor->peer_id_creation_time + (tor->session->peer_id_ttl_hours * 3600), tr_time()); + ttl = (int)difftime(tor->peer_id_creation_time + tor->session->peer_id_ttl_hours * 3600, tr_time()); } return ttl; @@ -541,7 +541,7 @@ void tr_torrentCheckSeedLimit(tr_torrent* tor) /* maybe notify the client */ if (tor->ratio_limit_hit_func != NULL) { - tor->ratio_limit_hit_func(tor, tor->ratio_limit_hit_func_user_data); + (*tor->ratio_limit_hit_func)(tor, tor->ratio_limit_hit_func_user_data); } } /* if we're seeding and reach our inactiviy limit, stop the torrent */ @@ -555,7 +555,7 @@ void tr_torrentCheckSeedLimit(tr_torrent* tor) /* maybe notify the client */ if (tor->idle_limit_hit_func != NULL) { - tor->idle_limit_hit_func(tor, tor->idle_limit_hit_func_user_data); + (*tor->idle_limit_hit_func)(tor, tor->idle_limit_hit_func_user_data); } } } @@ -920,9 +920,8 @@ static bool setLocalErrorIfFilesDisappeared(tr_torrent* tor) if (disappeared) { tr_deeplog_tor(tor, "%s", "[LAZY] uh oh, the files disappeared"); - tr_torrentSetLocalError(tor, "%s", - _( - "No data found! Ensure your drives are connected or use \"Set Location\". To re-download, remove the torrent and re-add it.")); + tr_torrentSetLocalError(tor, "%s", _("No data found! Ensure your drives are connected or use \"Set Location\". " + "To re-download, remove the torrent and re-add it.")); } return disappeared; @@ -1545,7 +1544,7 @@ static uint64_t countFileBytesCompleted(tr_torrent const* tor, tr_file_index_t i /* the first block */ if (tr_torrentBlockIsComplete(tor, first)) { - total += tor->blockSize - (f->offset % tor->blockSize); + total += tor->blockSize - f->offset % tor->blockSize; } /* the middle blocks */ @@ -1559,7 +1558,7 @@ static uint64_t countFileBytesCompleted(tr_torrent const* tor, tr_file_index_t i /* the last block */ if (tr_torrentBlockIsComplete(tor, last)) { - total += (f->offset + f->length) - ((uint64_t)tor->blockSize * last); + total += f->offset + f->length - (uint64_t)tor->blockSize * last; } } } @@ -2171,7 +2170,7 @@ static void fireCompletenessChange(tr_torrent* tor, tr_completeness status, bool if (tor->completeness_func != NULL) { - tor->completeness_func(tor, status, wasRunning, tor->completeness_func_user_data); + (*tor->completeness_func)(tor, status, wasRunning, tor->completeness_func_user_data); } } @@ -2434,7 +2433,7 @@ static void tr_torrentFireMetadataCompleted(tr_torrent* tor) if (tor->metadata_func != NULL) { - tor->metadata_func(tor, tor->metadata_func_user_data); + (*tor->metadata_func)(tor, tor->metadata_func_user_data); } } @@ -2668,7 +2667,7 @@ void tr_torrentGetBlockLocation(tr_torrent const* tor, tr_block_index_t block, t uint64_t pos = block; pos *= tor->blockSize; *piece = pos / tor->info.pieceSize; - *offset = pos - (*piece * tor->info.pieceSize); + *offset = pos - *piece * tor->info.pieceSize; *length = tr_torBlockCountBytes(tor, block); } @@ -2679,7 +2678,7 @@ tr_block_index_t _tr_block(tr_torrent const* tor, tr_piece_index_t index, uint32 assert(tr_isTorrent(tor)); ret = index; - ret *= (tor->info.pieceSize / tor->blockSize); + ret *= tor->info.pieceSize / tor->blockSize; ret += offset / tor->blockSize; return ret; } @@ -2757,7 +2756,7 @@ void tr_torGetPieceBlockRange(tr_torrent const* tor, tr_piece_index_t const piec uint64_t offset = tor->info.pieceSize; offset *= piece; *first = offset / tor->blockSize; - offset += (tr_torPieceCountBytes(tor, piece) - 1); + offset += tr_torPieceCountBytes(tor, piece) - 1; *last = offset / tor->blockSize; } @@ -3195,7 +3194,7 @@ static void deleteLocalData(tr_torrent* tor, tr_fileFunc func) if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0) { char* file = tr_buildPath(tmpdir, name, NULL); - func(file, NULL); + (*func)(file, NULL); tr_free(file); } } @@ -3211,7 +3210,7 @@ static void deleteLocalData(tr_torrent* tor, tr_fileFunc func) while (tr_sys_path_exists(walk, NULL) && !tr_sys_path_is_same(tmpdir, walk, NULL)) { char* tmp = tr_sys_path_dirname(walk, NULL); - func(walk, NULL); + (*func)(walk, NULL); tr_free(walk); walk = tmp; } @@ -3789,7 +3788,7 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, int pos) } } - tor->queuePosition = MIN(pos, (back + 1)); + tor->queuePosition = MIN(pos, back + 1); tor->anyDate = now; assert(queueIsSequenced(tor->session)); diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 9f67eab19..0aa1e6eeb 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -206,7 +206,7 @@ static void readFromPipe(evutil_socket_t fd, short eventType, void* veh) if (!eh->die && ngot == (ev_ssize_t)nwant) { dbgmsg("invoking function in libevent thread"); - (data.func)(data.user_data); + (*data.func)(data.user_data); } break; diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 499dc6447..f4992292f 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -1016,7 +1016,7 @@ static size_t quickfindPartition(char* base, size_t left, size_t right, size_t s for (i = left; i <= right - 1; ++i) { - if (compar(base + (size * i), base + (size * right)) <= 0) + if ((*compar)(base + (size * i), base + (size * right)) <= 0) { SWAP(base + (size * storeIndex), base + (size * i), size); ++storeIndex; @@ -1034,12 +1034,12 @@ static size_t quickfindPartition(char* base, size_t left, size_t right, size_t s for (i = left; i < storeIndex; ++i) { - assert(compar(base + (size * i), base + (size * storeIndex)) <= 0); + assert((*compar)(base + (size * i), base + (size * storeIndex)) <= 0); } for (i = storeIndex + 1; i <= right; ++i) { - assert(compar(base + (size * i), base + (size * storeIndex)) >= 0); + assert((*compar)(base + (size * i), base + (size * storeIndex)) >= 0); } #endif @@ -1076,7 +1076,7 @@ static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int for (i = 1; i < k; ++i) { - if (compar(base + (size * worstFirstPos), base + (size * i)) < 0) + if ((*compar)(base + (size * worstFirstPos), base + (size * i)) < 0) { worstFirstPos = i; } @@ -1084,12 +1084,12 @@ static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int for (i = 0; i < k; ++i) { - assert(compar(base + (size * i), base + (size * worstFirstPos)) <= 0); + assert((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0); } for (i = k; i < nmemb; ++i) { - assert(compar(base + (size * i), base + (size * worstFirstPos)) >= 0); + assert((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0); } } @@ -1372,7 +1372,7 @@ int tr_main_win32(int argc, char** argv, int (* real_main)(int, char**)) tr_win32_make_args_utf8(&argc, &argv); SetConsoleCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8); - return real_main(argc, argv); + return (*real_main)(argc, argv); } #endif diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 3a3aa2e0f..4d511aa0d 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -201,7 +201,7 @@ int tr_main_win32(int argc, char** argv, int (* real_main)(int, char**)); main_impl(__VA_ARGS__); \ int main(int argc, char* argv[]) \ { \ - return tr_main_win32(argc, argv, & main_impl); \ + return tr_main_win32(argc, argv, &main_impl); \ } \ int main_impl(__VA_ARGS__) @@ -249,13 +249,13 @@ void tr_free(void* p); void* tr_memdup(void const* src, size_t byteCount); #define tr_new(struct_type, n_structs) \ - ((struct_type*)tr_malloc(sizeof(struct_type)* ((size_t)(n_structs)))) + ((struct_type*)tr_malloc(sizeof(struct_type) * (size_t)(n_structs))) #define tr_new0(struct_type, n_structs) \ - ((struct_type*)tr_malloc0(sizeof(struct_type)* ((size_t)(n_structs)))) + ((struct_type*)tr_malloc0(sizeof(struct_type) * (size_t)(n_structs))) #define tr_renew(struct_type, mem, n_structs) \ - ((struct_type*)tr_realloc((mem), sizeof(struct_type)* ((size_t)(n_structs)))) + ((struct_type*)tr_realloc((mem), sizeof(struct_type) * (size_t)(n_structs))) void* tr_valloc(size_t bufLen); diff --git a/libtransmission/variant-json.c b/libtransmission/variant-json.c index ce62f813b..280663e2f 100644 --- a/libtransmission/variant-json.c +++ b/libtransmission/variant-json.c @@ -141,15 +141,15 @@ static bool decode_hex_string(char const* in, unsigned int* setme) if ('0' <= *in && *in <= '9') { - val += (*in - '0'); + val += *in - '0'; } else if ('a' <= *in && *in <= 'f') { - val += (*in - 'a') + 10u; + val += *in - 'a' + 10u; } else if ('A' <= *in && *in <= 'F') { - val += (*in - 'A') + 10u; + val += *in - 'A' + 10u; } else { diff --git a/libtransmission/variant.c b/libtransmission/variant.c index 7cb241978..19a54751e 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -1270,7 +1270,7 @@ int tr_variantFromBuf(tr_variant* setme, tr_variant_fmt fmt, void const* buf, si break; default /* TR_VARIANT_FMT_BENC */: - err = tr_variantParseBenc(buf, ((char const*)buf) + buflen, setme, setme_end); + err = tr_variantParseBenc(buf, (char const*)buf + buflen, setme, setme_end); break; } diff --git a/libtransmission/web.c b/libtransmission/web.c index 01d0f6ade..9481c817c 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -269,7 +269,7 @@ static void task_finish_func(void* vtask) if (task->done_func != NULL) { - task->done_func(task->session, task->did_connect, task->did_timeout, task->code, evbuffer_pullup(task->response, -1), + (*task->done_func)(task->session, task->did_connect, task->did_timeout, task->code, evbuffer_pullup(task->response, -1), evbuffer_get_length(task->response), task->done_func_user_data); } diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index cfbe787c8..4075ffa28 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -78,7 +78,7 @@ static void publish(tr_webseed* w, tr_peer_event* e) { if (w->callback != NULL) { - w->callback(&w->parent, e, w->callback_data); + (*w->callback)(&w->parent, e, w->callback_data); } } @@ -254,7 +254,7 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con data->webseed = w; data->real_url = tr_strdup(url); data->piece_index = task->piece_index; - data->piece_offset = task->piece_offset + (task->blocks_done * task->block_size) + (len - 1); + data->piece_offset = task->piece_offset + task->blocks_done * task->block_size + len - 1; /* processing this uses a tr_torrent pointer, so push the work to the libevent thread... */ @@ -345,7 +345,7 @@ static void on_idle(tr_webseed* w) task->webseed = w; task->block = b; task->piece_index = tr_torBlockPiece(tor, b); - task->piece_offset = (tor->blockSize * b) - (tor->info.pieceSize * task->piece_index); + task->piece_offset = tor->blockSize * b - tor->info.pieceSize * task->piece_index; task->length = (be - b) * tor->blockSize + tr_torBlockCountBytes(tor, be); task->blocks_done = 0; task->response_code = 0; @@ -474,7 +474,7 @@ static void task_request_next_chunk(struct tr_webseed_task* t) uint64_t const total_offset = tr_pieceOffset(tor, t->piece_index, t->piece_offset, t->length - remain); tr_piece_index_t const step_piece = total_offset / inf->pieceSize; - uint64_t const step_piece_offset = total_offset - (inf->pieceSize * step_piece); + uint64_t const step_piece_offset = total_offset - inf->pieceSize * step_piece; tr_file_index_t file_index; tr_file const* file; diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index cded80dd2..40be63741 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -364,6 +364,7 @@ void DetailsDialog::onTorrentChanged() namespace { + void setIfIdle(QComboBox* box, int i) { if (!box->hasFocus()) @@ -393,7 +394,8 @@ void setIfIdle(QSpinBox* spin, int value) spin->blockSignals(false); } } -} + +} // namespace void DetailsDialog::refresh() { diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index c397726fb..1ddef7292 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -157,8 +157,8 @@ void FilterBar::refreshTrackers() // update the "All" row myTrackerModel->setData(myTrackerModel->index(0, 0), myTorrents.rowCount(), FilterBarComboBox::CountRole); - myTrackerModel->setData(myTrackerModel->index(0, 0), getCountString( - myTorrents.rowCount()), FilterBarComboBox::CountStringRole); + myTrackerModel->setData(myTrackerModel->index(0, 0), getCountString(myTorrents.rowCount()), + FilterBarComboBox::CountStringRole); // rows to update for (QString const& host : oldHosts & newHosts) diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index a0573e913..f04f5c38f 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -572,6 +572,9 @@ void MainWindow::setLocation() d->show(); } +namespace +{ + // Open Folder & select torrent's file or top folder #undef HAVE_OPEN_SELECT @@ -611,6 +614,8 @@ static void openSelect(QString const& path) #endif +} // namespace + void MainWindow::openFolder() { QSet const selectedTorrents = getSelectedTorrents(); diff --git a/qt/TrackerDelegate.cc b/qt/TrackerDelegate.cc index cc27b73df..63e5f2a80 100644 --- a/qt/TrackerDelegate.cc +++ b/qt/TrackerDelegate.cc @@ -169,7 +169,7 @@ QString timeToStringRounded(int seconds) { if (seconds > 60) { - seconds -= (seconds % 60); + seconds -= seconds % 60; } return Formatter::timeToString(seconds); diff --git a/utils/edit.c b/utils/edit.c index 8f3a25de3..050612935 100644 --- a/utils/edit.c +++ b/utils/edit.c @@ -114,7 +114,7 @@ static bool removeURL(tr_variant* metainfo, char const* url) { if (tr_variantGetStr(node, &str, NULL) && strcmp(str, url) == 0) { - printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex + 1)); + printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, tierIndex + 1); tr_variantListRemove(tier, nodeIndex); changed = true; } @@ -126,7 +126,7 @@ static bool removeURL(tr_variant* metainfo, char const* url) if (tr_variantListSize(tier) == 0) { - printf("\tNo URLs left in tier #%d... removing tier\n", (tierIndex + 1)); + printf("\tNo URLs left in tier #%d... removing tier\n", tierIndex + 1); tr_variantListRemove(announce_list, tierIndex); } else