case 'w':
{
- tr_variant* args = tadd ? tr_variantDictFind(tadd, TR_KEY_arguments) : ensure_sset(&sset);
+ tr_variant* args = tadd != NULL ? tr_variantDictFind(tadd, TR_KEY_arguments) : ensure_sset(&sset);
tr_variantDictAddStr(args, TR_KEY_download_dir, optarg);
break;
}
}
else
{
- char const* baseline = infos[0]->comment ? infos[0]->comment : "";
+ char const* baseline = infos[0]->comment != NULL ? infos[0]->comment : "";
for (i = 1; i < n; ++i)
{
- if (g_strcmp0(baseline, infos[i]->comment ? infos[i]->comment : "") != 0)
+ if (g_strcmp0(baseline, infos[i]->comment != NULL ? infos[i]->comment : "") != 0)
{
break;
}
char unver[64];
char total[64];
char avail[32];
- double const d = sizeWhenDone ? (100.0 * available) / sizeWhenDone : 0;
- double const ratio = 100.0 * (sizeWhenDone ? (haveValid + haveUnchecked) / (double)sizeWhenDone : 1);
+ double const d = sizeWhenDone != 0 ? (100.0 * available) / sizeWhenDone : 0;
+ double const ratio = 100.0 * (sizeWhenDone != 0 ? (haveValid + haveUnchecked) / (double)sizeWhenDone : 1);
tr_strlpercent(avail, d, sizeof(avail));
tr_strlpercent(buf2, ratio, sizeof(buf2));
{
tr_torrent* tor = refresh_data->tor;
tr_info const* inf = tr_torrentInfo(tor);
- int const enabled = !inf->files[index].dnd;
+ int const enabled = inf->files[index].dnd ? 0 : 1;
int const priority = inf->files[index].priority;
uint64_t const have = refresh_data->refresh_file_stat[index].bytesCompleted;
- int const prog = size ? (int)((100.0 * have) / size) : 1;
+ int const prog = size != 0 ? (int)(100.0 * have / size) : 1;
if (priority != old_priority || enabled != old_enabled || have != old_have || prog != old_prog)
{
{
GNode* child = parent->children;
- while (child)
+ while (child != NULL)
{
struct row_struct const* child_data = child->data;
for (i = 0, n = G_N_ELEMENTS(types); i < n; ++i)
{
- char const* name = types[i].context ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name);
+ char const* name = types[i].context != NULL ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name);
gtk_list_store_insert_with_values(store, NULL, -1,
ACTIVITY_FILTER_COL_NAME, name,
ACTIVITY_FILTER_COL_TYPE, types[i].type,
/* test the torrent name... */
{
char* pch = g_utf8_casefold(tr_torrentName(tor), -1);
- ret = !key || strstr(pch, key) != NULL;
+ ret = key == NULL || strstr(pch, key) != NULL;
g_free(pch);
}
for (i = 0; i < inf->fileCount && !ret; ++i)
{
char* pch = g_utf8_casefold(inf->files[i].name, -1);
- ret = !key || strstr(pch, key) != NULL;
+ ret = key == NULL || strstr(pch, key) != NULL;
g_free(pch);
}
}
GtkIconTheme* icon_theme;
int icon_size;
GHashTable* cache;
-} IconCache;
+}
+IconCache;
static IconCache* icon_cache[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
if (pixbuf == NULL)
{
- if (error && error->message)
+ if (error != NULL && error->message != NULL)
{
g_warning("could not load icon pixbuf: %s\n", error->message);
}
static void updatePiecesLabel(MakeMetaUI* ui)
{
tr_metainfo_builder const* builder = ui->builder;
- char const* filename = builder ? builder->top : NULL;
+ char const* filename = builder != NULL ? builder->top : NULL;
GString* gstr = g_string_new(NULL);
g_string_append(gstr, "<i>");
break;
case TR_PARSE_DUPLICATE:
-
/* don't complain about .torrent files in the watch directory
* that have already been added... that gets annoying and we
* don't want to be nagging users to clean up their watch dirs */
break;
default:
-
if (do_prompt)
{
g_signal_emit(core, signals[ADD_PROMPT_SIGNAL], 0, ctor);
else
{
char* errmsg;
- size_t const buflen = buf ? evbuffer_get_length(buf) : 0;
+ size_t const buflen = buf != NULL ? evbuffer_get_length(buf) : 0;
if (action == TAU_ACTION_ERROR && buflen > 0)
{
int n;
tr_ptrArray* reqs;
time_t const now = time(NULL);
- bool const cancel_all = tracker->close_at && (tracker->close_at <= now);
+ bool const cancel_all = tracker->close_at != 0 && (tracker->close_at <= now);
if (tracker->connecting_at != 0 && tracker->connecting_at + TAU_REQUEST_TTL < now)
{
}
/* traverse & repeat for the subtree */
- if (1)
+ if (true)
{
int i;
struct tr_bandwidth** children = (struct tr_bandwidth**)tr_ptrArrayBase(&b->children);
static bool tr_bitfieldEnsureNthBitAlloced(tr_bitfield* b, size_t nth)
{
/* count is zero-based, so we need to allocate nth+1 bits before setting the nth */
-
if (nth == SIZE_MAX)
{
return false;
static inline bool tr_bitfieldHasAll(tr_bitfield const* b)
{
- return b->bit_count ? (b->true_count == b->bit_count) : b->have_all_hint;
+ return b->bit_count != 0 ? (b->true_count == b->bit_count) : b->have_all_hint;
}
static inline bool tr_bitfieldHasNone(tr_bitfield const* b)
{
- return b->bit_count ? (b->true_count == 0) : b->have_none_hint;
+ return b->bit_count != 0 ? (b->true_count == 0) : b->have_none_hint;
}
bool tr_bitfieldHas(tr_bitfield const* b, size_t n);
tr_sha1_ctx_t tr_sha1_init(void)
{
- API(sha1_context) * handle = tr_new0(API(sha1_context), 1);
+ API(sha1_context)* handle = tr_new0(API(sha1_context), 1);
#if API_VERSION_NUMBER >= 0x01030800
API(sha1_init)(handle);
tr_rc4_ctx_t tr_rc4_new(void)
{
- API(arc4_context) * handle = tr_new0(API(arc4_context), 1);
+ API(arc4_context)* handle = tr_new0(API(arc4_context), 1);
#if API_VERSION_NUMBER >= 0x01030800
API(arc4_init)(handle);
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
size_t generator_num_length)
{
- API(dhm_context) * handle = tr_new0(API(dhm_context), 1);
+ API(dhm_context)* handle = tr_new0(API(dhm_context), 1);
assert(prime_num != NULL);
assert(generator_num != NULL);
bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t* public_key, size_t* public_key_length)
{
- API(dhm_context) * handle = raw_handle;
+ API(dhm_context)* handle = raw_handle;
assert(handle != NULL);
assert(public_key != NULL);
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_key, size_t other_public_key_length)
{
- API(dhm_context) * handle = raw_handle;
+ API(dhm_context)* handle = raw_handle;
struct tr_dh_secret* ret;
size_t secret_key_length;
struct sockaddr_storage sock;
assert(tr_isSession(s));
- assert(addr);
- assert(port);
+ assert(addr != NULL);
+ assert(port != NULL);
ensureSessionFdInfoExists(s);
gFd = s->fdInfo;
(void)permissions;
- if (flags & TR_SYS_FILE_READ)
+ if ((flags & TR_SYS_FILE_READ) != 0)
{
native_access |= GENERIC_READ;
}
- if (flags & TR_SYS_FILE_WRITE)
+ if ((flags & TR_SYS_FILE_WRITE)) != 0
{
native_access |= GENERIC_WRITE;
}
- if (flags & TR_SYS_FILE_CREATE_NEW)
+ if ((flags & TR_SYS_FILE_CREATE_NEW)) != 0
{
native_disposition = CREATE_NEW;
}
- else if (flags & TR_SYS_FILE_CREATE)
+ else if ((flags & TR_SYS_FILE_CREATE)) != 0
{
- native_disposition = flags & TR_SYS_FILE_TRUNCATE ? CREATE_ALWAYS : OPEN_ALWAYS;
+ native_disposition = (flags & TR_SYS_FILE_TRUNCATE) != 0 ? CREATE_ALWAYS : OPEN_ALWAYS;
}
- else if (flags & TR_SYS_FILE_TRUNCATE)
+ else if ((flags & TR_SYS_FILE_TRUNCATE)) != 0
{
native_disposition = TRUNCATE_EXISTING;
}
- if (flags & TR_SYS_FILE_SEQUENTIAL)
+ if ((flags & TR_SYS_FILE_SEQUENTIAL)) != 0
{
native_flags |= FILE_FLAG_SEQUENTIAL_SCAN;
}
success = ret != TR_BAD_SYS_FILE;
- if (success && (flags & TR_SYS_FILE_APPEND))
+ if (success && (flags & TR_SYS_FILE_APPEND) != 0)
{
success = SetFilePointer(ret, 0, NULL, FILE_END) != INVALID_SET_FILE_POINTER;
}
uint16_t padc_len = 0;
uint32_t crypto_provide = 0;
tr_torrent* tor;
- size_t const needlen = SHA_DIGEST_LENGTH + /* HASH('req1',s) */
+ size_t const needlen = SHA_DIGEST_LENGTH + /* HASH('req1', s) */
SHA_DIGEST_LENGTH + /* HASH('req2', SKEY) xor HASH('req3', S) */
VC_LENGTH + sizeof(crypto_provide) + sizeof(padc_len);
for (l = *list; l != NULL; l = l->next)
{
- int const c = (compare)(data, l->data);
+ int const c = (*compare)(data, l->data);
if (c <= 0)
{
return "pieces";
}
- if (len % SHA_DIGEST_LENGTH)
+ if (len % SHA_DIGEST_LENGTH != 0)
{
return "pieces";
}
state = -1;
tr_torrentSetLocation(tor, target_dir, true, NULL, &state);
- while ((state == TR_LOC_MOVING) && (time(NULL) <= deadline))
+ while (state == TR_LOC_MOVING && time(NULL) <= deadline)
{
tr_wait_msec(50);
}
{
tr_swarm* s = vs;
- assert(s);
+ assert(s != NULL);
assert(!s->isRunning);
assert(swarmIsLocked(s));
assert(tr_ptrArrayEmpty(&s->outgoingHandshakes));
{
#if 0
- assert(t);
- assert(peer);
- assert(peer->msgs);
+ assert(t != NULL);
+ assert(peer != NULL);
+ assert(peer->msgs != NULL);
/* is this a valid piece? */
if (pieceIndex >= t->tor->info.pieceCount)
qsort(pex, count, sizeof(tr_pex), tr_pexCompare);
- assert((walk - pex) == count);
+ assert(walk - pex == count);
*setme_pex = pex;
/* cleanup */
char const* pkg = PACKAGE_DATA_DIR;
char* xdg = tr_env_get_string("XDG_DATA_DIRS", NULL);
char const* fallback = "/usr/local/share:/usr/share";
- char* buf = tr_strdup_printf("%s:%s:%s", (pkg ? pkg : ""), (xdg ? xdg : ""), fallback);
+ char* buf = tr_strdup_printf("%s:%s:%s", pkg != NULL ? pkg : "", xdg != NULL ? xdg : "", fallback);
tr_free(xdg);
tmp = buf;
bool tr_ctorGetSave(tr_ctor const* ctor)
{
- return ctor && ctor->saveInOurTorrentsDir;
+ return ctor != NULL && ctor->saveInOurTorrentsDir;
}
void tr_ctorSetPaused(tr_ctor* ctor, tr_ctorMode mode, bool isPaused)
{
uint64_t const u = tor->uploadedCur + tor->uploadedPrev;
uint64_t const d = tor->downloadedCur + tor->downloadedPrev;
- uint64_t const baseline = d ? d : tr_cpSizeWhenDone(&tor->completion);
+ uint64_t const baseline = d != 0 ? d : tr_cpSizeWhenDone(&tor->completion);
uint64_t const goal = baseline * seedRatio;
if (setmeLeft != NULL)
static bool tr_torrentIsSeedRatioDone(tr_torrent const* tor)
{
uint64_t bytesLeft;
- return tr_torrentGetSeedRatioBytes(tor, &bytesLeft, NULL) && !bytesLeft;
+ return tr_torrentGetSeedRatioBytes(tor, &bytesLeft, NULL) && bytesLeft == 0;
}
/***
{
assert(tr_isTorrent(tor));
- if ((tab != NULL) && (size > 0))
+ if (tab != NULL && size > 0)
{
tr_peerMgrTorrentAvailability(tor, tab, size);
}
(unsigned long)length, err);
}
- return !err;
+ return err == 0;
}
uint64_t tr_pieceOffset(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length)
if ((type & EV_READ) != 0)
{
struct sockaddr_in foreignAddr;
- int addrLen = sizeof foreignAddr;
+ int addrLen = sizeof(foreignAddr);
char foreignMsg[lpd_maxDatagramLength + 1];
/* process local announcement from foreign peer */
}
ipv6:
-
if (tr_globalIPv6())
{
rebind_ipv6(ss, true);
if (real_impl != NULL)
{
- return real_impl(handle, overlapped, bytes_transferred, timeout, alertable);
+ return (*real_impl)(handle, overlapped, bytes_transferred, timeout, alertable);
}
DWORD const wait_result = WaitForSingleObjectEx(handle, timeout, alertable);
return TR_WATCHDIR_IGNORE;
}
- tr_watchdir_status const ret = handle->callback(handle, name, handle->callback_user_data);
+ tr_watchdir_status const ret = (*handle->callback)(handle, name, handle->callback_user_data);
assert(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
tr_sys_dir_t dir;
char const* name;
tr_ptrArray new_dir_entries = TR_PTR_ARRAY_INIT_STATIC;
- PtrArrayCompareFunc const name_compare_func = (PtrArrayCompareFunc) & strcmp;
+ PtrArrayCompareFunc const name_compare_func = (PtrArrayCompareFunc)&strcmp;
tr_error* error = NULL;
if ((dir = tr_sys_dir_open(handle->path, &error)) == TR_BAD_SYS_DIR)
else
{
QStyleOptionViewItem disabledOption = option;
- QPalette::ColorRole const disabledColorRole = (disabledOption.state & QStyle::State_Selected) ?
+ QPalette::ColorRole const disabledColorRole = (disabledOption.state & QStyle::State_Selected) != 0 ?
QPalette::HighlightedText : QPalette::Text;
disabledOption.palette.setColor(disabledColorRole, Utils::getFadedColor(disabledOption.palette.color(
disabledColorRole)));
{
bool const isMagnet(!tor.hasMetadata());
myProgressBarStyle->direction = option.direction;
- myProgressBarStyle->progress = static_cast<int>(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() :
- tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
+ myProgressBarStyle->progress = static_cast<int>(myProgressBarStyle->minimum + (isMagnet ? tor.metadataPercentDone() :
+ tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum));
}
}
// clear out any remnants of the previous watcher, if any
myWatchDirFiles.clear();
- if (myWatcher)
+ if (myWatcher != nullptr)
{
delete myWatcher;
myWatcher = nullptr;