fix: more sonarcloud warnings (#2324)

This commit is contained in:
Charles Kerr 2021-12-16 23:47:51 -06:00 committed by GitHub
parent b9406dfebb
commit 37a8046ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 91 additions and 120 deletions

View File

@ -27,7 +27,7 @@ constexpr size_t getBytesNeeded(size_t bit_count)
return (bit_count >> 3) + ((bit_count & 7) != 0 ? 1 : 0);
}
static void setAllTrue(uint8_t* array, size_t bit_count)
void setAllTrue(uint8_t* array, size_t bit_count)
{
uint8_t constexpr Val = 0xFF;
size_t const n = getBytesNeeded(bit_count);

View File

@ -95,7 +95,7 @@ void tr_completion::amountDone(float* tab, size_t n_tabs) const
auto const begin = i * blocks_per_tab;
auto const end = std::min(begin + blocks_per_tab, std::size(blocks_));
auto const numerator = blocks_.count(begin, end);
tab[i] = (double)numerator / (end - begin);
tab[i] = float(numerator) / (end - begin);
}
}

View File

@ -93,8 +93,7 @@ int tr_rand_int(int upper_bound)
{
TR_ASSERT(upper_bound > 0);
unsigned int noise = 0;
if (tr_rand_buffer(&noise, sizeof(noise)))
if (unsigned int noise = 0; tr_rand_buffer(&noise, sizeof(noise)))
{
return noise % upper_bound;
}

View File

@ -81,7 +81,7 @@ bool tr_cryptoComputeSecret(tr_crypto* crypto, uint8_t const* peerPublicKey)
uint8_t const* tr_cryptoGetMyPublicKey(tr_crypto const* crypto, int* setme_len)
{
ensureKeyExists((tr_crypto*)crypto);
ensureKeyExists(const_cast<tr_crypto*>(crypto));
*setme_len = KEY_LEN;
return crypto->myPublicKey;
}

View File

@ -19,7 +19,7 @@ tr_error* tr_error_new_literal(int code, char const* message)
{
TR_ASSERT(message != nullptr);
tr_error* error = tr_new(tr_error, 1);
auto* const error = tr_new(tr_error, 1);
error->code = code;
error->message = tr_strdup(message);
@ -32,7 +32,7 @@ static tr_error* tr_error_new_valist(int code, char const* message_format, va_li
{
TR_ASSERT(message_format != nullptr);
tr_error* error = tr_new(tr_error, 1);
auto* const error = tr_new(tr_error, 1);
error->code = code;
error->message = tr_strdup_vprintf(message_format, args);

View File

@ -7,6 +7,7 @@
*/
#include <algorithm>
#include <array>
#include <cerrno>
#include <cinttypes>
#include <cstring>
@ -85,18 +86,17 @@ static bool preallocate_file_full(tr_sys_file_t fd, uint64_t length, tr_error**
if (!TR_ERROR_IS_ENOSPC(my_error->code))
{
uint8_t buf[4096];
auto buf = std::array<uint8_t, 4096>{};
bool success = true;
memset(buf, 0, sizeof(buf));
tr_error_clear(&my_error);
/* fallback: the old-fashioned way */
while (success && length > 0)
{
uint64_t const thisPass = std::min(length, uint64_t{ sizeof(buf) });
uint64_t const thisPass = std::min(length, uint64_t{ std::size(buf) });
uint64_t bytes_written = 0;
success = tr_sys_file_write(fd, buf, thisPass, &bytes_written, &my_error);
success = tr_sys_file_write(fd, std::data(buf), thisPass, &bytes_written, &my_error);
length -= bytes_written;
}
@ -251,17 +251,15 @@ static int cached_file_open(
return 0;
FAIL:
int const err = error->code;
tr_error_free(error);
if (fd != TR_BAD_SYS_FILE)
{
int const err = error->code;
tr_error_free(error);
if (fd != TR_BAD_SYS_FILE)
{
tr_sys_file_close(fd, nullptr);
}
return err;
tr_sys_file_close(fd, nullptr);
}
return err;
}
/***
@ -479,9 +477,7 @@ tr_sys_file_t tr_fdFileCheckout(
if (!cached_file_is_open(o))
{
int const err = cached_file_open(o, filename, writable, allocation, file_size);
if (err != 0)
if (int const err = cached_file_open(o, filename, writable, allocation, file_size); err != 0)
{
errno = err;
return TR_BAD_SYS_FILE;

View File

@ -57,9 +57,7 @@ tr_sys_file_t tr_logGetFile(void)
if (!initialized)
{
int const fd = tr_env_get_int("TR_DEBUG_FD", 0);
switch (fd)
switch (tr_env_get_int("TR_DEBUG_FD", 0))
{
case 1:
file = tr_sys_file_get_std(TR_STD_SYS_FILE_OUT, nullptr);
@ -68,6 +66,10 @@ tr_sys_file_t tr_logGetFile(void)
case 2:
file = tr_sys_file_get_std(TR_STD_SYS_FILE_ERR, nullptr);
break;
default:
file = TR_BAD_SYS_FILE;
break;
}
initialized = true;
@ -124,7 +126,7 @@ char* tr_logGetTimeStr(char* buf, size_t buflen)
struct timeval tv;
tr_gettimeofday(&tv);
time_t const seconds = tv.tv_sec;
int const milliseconds = (int)(tv.tv_usec / 1000);
auto const milliseconds = int(tv.tv_usec / 1000);
char msec_str[8];
tr_snprintf(msec_str, sizeof msec_str, "%03d", milliseconds);

View File

@ -54,17 +54,15 @@ static struct FileList* getFiles(char const* dir, char const* base, struct FileL
tr_sys_path_native_separators(std::data(buf));
tr_sys_path_info info;
tr_error* error = nullptr;
if (!tr_sys_path_get_info(buf.c_str(), 0, &info, &error))
if (tr_error* error = nullptr; !tr_sys_path_get_info(buf.c_str(), 0, &info, &error))
{
tr_logAddError(_("Torrent Creator is skipping file \"%s\": %s"), buf.c_str(), error->message);
tr_error_free(error);
return list;
}
tr_sys_dir_t odir = info.type == TR_SYS_PATH_IS_DIRECTORY ? tr_sys_dir_open(buf.c_str(), nullptr) : TR_BAD_SYS_DIR;
if (odir != TR_BAD_SYS_DIR)
if (tr_sys_dir_t odir = info.type == TR_SYS_PATH_IS_DIRECTORY ? tr_sys_dir_open(buf.c_str(), nullptr) : TR_BAD_SYS_DIR;
odir != TR_BAD_SYS_DIR)
{
char const* name = nullptr;
while ((name = tr_sys_dir_read_name(odir, nullptr)) != nullptr)
@ -79,7 +77,7 @@ static struct FileList* getFiles(char const* dir, char const* base, struct FileL
}
else if (info.type == TR_SYS_PATH_IS_FILE && info.size > 0)
{
struct FileList* node = tr_new(struct FileList, 1);
auto* const node = tr_new0(FileList, 1);
node->size = info.size;
node->filename = tr_strvDup(buf);
node->next = list;
@ -128,14 +126,6 @@ static uint32_t bestPieceSize(uint64_t totalSize)
return 32 * KiB; /* less than 50 meg */
}
static int builderFileCompare(void const* va, void const* vb)
{
auto const* a = static_cast<tr_metainfo_builder_file const*>(va);
auto const* b = static_cast<tr_metainfo_builder_file const*>(vb);
return evutil_ascii_strcasecmp(a->filename, b->filename);
}
tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
{
char* const real_top = tr_sys_path_resolve(topFileArg, nullptr);
@ -146,7 +136,7 @@ tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
return nullptr;
}
tr_metainfo_builder* ret = tr_new0(tr_metainfo_builder, 1);
auto* const ret = tr_new0(tr_metainfo_builder, 1);
ret->top = real_top;
@ -188,7 +178,10 @@ tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
tr_free(tmp);
}
qsort(ret->files, ret->fileCount, sizeof(tr_metainfo_builder_file), builderFileCompare);
std::sort(
ret->files,
ret->files + ret->fileCount,
[](auto const& a, auto const& b) { return evutil_ascii_strcasecmp(a.filename, b.filename) < 0; });
tr_metaInfoBuilderSetPieceSize(ret, bestPieceSize(ret->totalSize));
@ -257,7 +250,7 @@ void tr_metaInfoBuilderFree(tr_metainfo_builder* builder)
static uint8_t* getHashInfo(tr_metainfo_builder* b)
{
uint32_t fileIndex = 0;
uint8_t* ret = tr_new0(uint8_t, SHA_DIGEST_LENGTH * b->pieceCount);
auto* const ret = tr_new0(uint8_t, SHA_DIGEST_LENGTH * b->pieceCount);
uint8_t* walk = ret;
uint64_t off = 0;
tr_error* error = nullptr;
@ -403,8 +396,7 @@ static void makeInfoDict(tr_variant* dict, tr_metainfo_builder* builder)
tr_variantDictAddInt(dict, TR_KEY_length, builder->files[0].size);
}
char* const base = tr_sys_path_basename(builder->top, nullptr);
if (base != nullptr)
if (auto* const base = tr_sys_path_basename(builder->top, nullptr); base != nullptr)
{
tr_variantDictAddStr(dict, TR_KEY_name, base);
tr_free(base);
@ -412,8 +404,7 @@ static void makeInfoDict(tr_variant* dict, tr_metainfo_builder* builder)
tr_variantDictAddInt(dict, TR_KEY_piece_length, builder->pieceSize);
uint8_t* const pch = getHashInfo(builder);
if (pch != nullptr)
if (auto* const pch = getHashInfo(builder); pch != nullptr)
{
tr_variantDictAddRaw(dict, TR_KEY_pieces, pch, SHA_DIGEST_LENGTH * builder->pieceCount);
tr_free(pch);

View File

@ -119,9 +119,8 @@ static auto getTorrents(tr_session* session, tr_variant* args)
auto id = int64_t{};
auto sv = std::string_view{};
tr_variant* ids = nullptr;
if (tr_variantDictFindList(args, TR_KEY_ids, &ids))
if (tr_variant* ids = nullptr; tr_variantDictFindList(args, TR_KEY_ids, &ids))
{
size_t const n = tr_variantListSize(ids);
torrents.reserve(n);
@ -148,8 +147,7 @@ static auto getTorrents(tr_session* session, tr_variant* args)
}
else if (tr_variantDictFindInt(args, TR_KEY_ids, &id) || tr_variantDictFindInt(args, TR_KEY_id, &id))
{
tr_torrent* const tor = tr_torrentFindFromId(session, id);
if (tor != nullptr)
if (auto* const tor = tr_torrentFindFromId(session, id); tor != nullptr)
{
torrents.push_back(tor);
}
@ -165,7 +163,7 @@ static auto getTorrents(tr_session* session, tr_variant* args)
std::begin(session->torrents),
std::end(session->torrents),
std::back_inserter(torrents),
[&cutoff](tr_torrent* tor) { return tor->anyDate >= cutoff; });
[&cutoff](auto const* tor) { return tor->anyDate >= cutoff; });
}
else
{
@ -454,7 +452,7 @@ static void addTrackerStats(tr_tracker_view const& tracker, tr_variant* list)
tr_variantDictAddInt(d, TR_KEY_tier, tracker.tier);
}
static void addPeers(tr_torrent* tor, tr_variant* list)
static void addPeers(tr_torrent const* tor, tr_variant* list)
{
auto peerCount = int{};
tr_peer_stat* peers = tr_torrentPeers(tor, &peerCount);

View File

@ -81,9 +81,9 @@ static auto constexpr SaveIntervalSecs = int{ 360 };
#define dbgmsg(...) tr_logAddDeepNamed(nullptr, __VA_ARGS__)
static tr_port getRandomPort(tr_session* s)
static tr_port getRandomPort(tr_session const* s)
{
return tr_rand_int_weak(s->randomPortHigh - s->randomPortLow + 1) + s->randomPortLow;
return tr_port(tr_rand_int_weak(s->randomPortHigh - s->randomPortLow + 1) + s->randomPortLow);
}
/* Generate a peer id : "-TRxyzb-" + 12 random alphanumeric
@ -397,7 +397,7 @@ void tr_sessionGetDefaultSettings(tr_variant* d)
tr_variantDictAddBool(d, TR_KEY_anti_brute_force_enabled, true);
}
void tr_sessionGetSettings(tr_session* s, tr_variant* d)
void tr_sessionGetSettings(tr_session const* s, tr_variant* d)
{
TR_ASSERT(tr_variantIsDict(d));

View File

@ -152,6 +152,20 @@ static wchar_t** to_wide_env(std::map<std::string_view, std::string_view> const&
return wide_env;
}
static void tr_free_ptrv(void* const* p)
{
if (p == nullptr)
{
return;
}
while (*p != nullptr)
{
tr_free(*p);
++p;
}
}
static bool create_env_block(std::map<std::string_view, std::string_view> const& env, wchar_t** env_block, tr_error** error)
{
wchar_t** wide_env = to_wide_env(env);

View File

@ -446,7 +446,7 @@ bool tr_torrentGetSeedIdle(tr_torrent const* tor, uint16_t* idleMinutes)
return isLimited;
}
static bool tr_torrentIsSeedIdleLimitDone(tr_torrent* tor)
static bool tr_torrentIsSeedIdleLimitDone(tr_torrent const* tor)
{
auto idleMinutes = uint16_t{};
return tr_torrentGetSeedIdle(tor, &idleMinutes) &&
@ -641,7 +641,7 @@ static void torrentCallScript(tr_torrent const* tor, char const* script);
static void callScriptIfEnabled(tr_torrent const* tor, TrScript type)
{
auto* session = tor->session;
auto const* session = tor->session;
if (tr_sessionIsScriptEnabled(session, type))
{
@ -1129,15 +1129,15 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
if (!seedRatioApplies || s->finished)
{
s->seedRatioPercentDone = 1;
s->seedRatioPercentDone = 1.0F;
}
else if (seedRatioBytesGoal == 0) /* impossible? safeguard for div by zero */
{
s->seedRatioPercentDone = 0;
s->seedRatioPercentDone = 0.0F;
}
else
{
s->seedRatioPercentDone = (double)(seedRatioBytesGoal - seedRatioBytesLeft) / seedRatioBytesGoal;
s->seedRatioPercentDone = float(seedRatioBytesGoal - seedRatioBytesLeft) / seedRatioBytesGoal;
}
/* test some of the constraints */
@ -1488,9 +1488,8 @@ struct verify_data
static void onVerifyDoneThreadFunc(void* vdata)
{
auto* data = static_cast<struct verify_data*>(vdata);
tr_torrent* tor = data->tor;
if (!tor->isDeleting)
if (auto* const tor = data->tor; !tor->isDeleting)
{
if (!data->aborted)
{
@ -1565,7 +1564,7 @@ static void verifyTorrent(void* vdata)
void tr_torrentVerify(tr_torrent* tor, tr_verify_done_func callback_func, void* callback_data)
{
struct verify_data* const data = tr_new(struct verify_data, 1);
auto* const data = tr_new(struct verify_data, 1);
data->tor = tor;
data->aborted = false;
data->callback_func = callback_func;
@ -1682,7 +1681,7 @@ static void tr_torrentDeleteLocalData(tr_torrent*, tr_fileFunc);
static void removeTorrent(void* vdata)
{
auto* data = static_cast<struct remove_data*>(vdata);
auto* const data = static_cast<struct remove_data*>(vdata);
auto const lock = data->tor->unique_lock();
if (data->deleteFlag)
@ -1701,7 +1700,7 @@ void tr_torrentRemove(tr_torrent* tor, bool deleteFlag, tr_fileFunc deleteFunc)
tor->isDeleting = true;
struct remove_data* data = tr_new0(struct remove_data, 1);
auto* const data = tr_new0(struct remove_data, 1);
data->tor = tor;
data->deleteFlag = deleteFlag;
data->deleteFunc = deleteFunc;
@ -2329,8 +2328,7 @@ static void deleteLocalData(tr_torrent* tor, tr_fileFunc func)
***/
/* try deleting the local data's top-level files & folders */
tr_sys_dir_t const odir = tr_sys_dir_open(tmpdir.c_str(), nullptr);
if (odir != TR_BAD_SYS_DIR)
if (auto const odir = tr_sys_dir_open(tmpdir.c_str(), nullptr); odir != TR_BAD_SYS_DIR)
{
char const* name = nullptr;
while ((name = tr_sys_dir_read_name(odir, nullptr)) != nullptr)
@ -2977,7 +2975,7 @@ static tr_file_index_t* renameFindAffectedFiles(tr_torrent* tor, char const* old
{
auto const n_files = tor->fileCount();
auto n_affected_files = size_t{};
tr_file_index_t* indices = tr_new0(tr_file_index_t, n_files);
auto* const indices = tr_new0(tr_file_index_t, n_files);
auto const oldpath_len = strlen(oldpath);

View File

@ -154,7 +154,7 @@ void tr_sessionGetDefaultSettings(struct tr_variant* setme_dictionary);
* @param setme_dictionary the dictionary to populate
* @see tr_sessionGetDefaultSettings()
*/
void tr_sessionGetSettings(tr_session* session, struct tr_variant* setme_dictionary);
void tr_sessionGetSettings(tr_session const* session, struct tr_variant* setme_dictionary);
/**
* Load settings from the configuration directory's settings.json file,

View File

@ -192,20 +192,6 @@ void tr_free(void* p)
}
}
void tr_free_ptrv(void* const* p)
{
if (p == nullptr)
{
return;
}
while (*p != nullptr)
{
tr_free(*p);
++p;
}
}
void* tr_memdup(void const* src, size_t byteCount)
{
return memcpy(tr_malloc(byteCount), src, byteCount);
@ -280,7 +266,6 @@ void tr_timerAddMsec(struct event* timer, int msec)
***
**/
// TODO: return a std::vector<>
uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
{
char const* const err_fmt = _("Couldn't read \"%1$s\": %2$s");
@ -483,7 +468,7 @@ tr_disk_space tr_dirSpace(std::string_view dir)
char* evbuffer_free_to_str(struct evbuffer* buf, size_t* result_len)
{
size_t const n = evbuffer_get_length(buf);
char* ret = tr_new(char, n + 1);
auto* const ret = tr_new(char, n + 1);
evbuffer_copyout(buf, ret, n);
evbuffer_free(buf);
ret[n] = '\0';
@ -1190,8 +1175,7 @@ double tr_truncd(double x, int precision)
char buf[128];
tr_snprintf(buf, sizeof(buf), "%.*f", TR_ARG_TUPLE(DBL_DIG, x));
char* const pt = strstr(buf, localeconv()->decimal_point);
if (pt != nullptr)
if (auto* const pt = strstr(buf, localeconv()->decimal_point); pt != nullptr)
{
pt[precision != 0 ? precision + 1 : 0] = '\0';
}
@ -1462,15 +1446,14 @@ void tr_formatter_speed_init(size_t kilo, char const* kb, char const* mb, char c
char* tr_formatter_speed_KBps(char* buf, double KBps, size_t buflen)
{
double const K = speed_units[TR_FMT_KB].value;
double speed = KBps;
if (speed <= 999.95) /* 0.0 KB to 999.9 KB */
if (auto speed = KBps; speed <= 999.95) /* 0.0 KB to 999.9 KB */
{
tr_snprintf(buf, buflen, "%d %s", (int)speed, speed_units[TR_FMT_KB].name);
}
else
{
double const K = speed_units[TR_FMT_KB].value;
speed /= K;
if (speed <= 99.995) /* 0.98 MB to 99.99 MB */
@ -1563,9 +1546,7 @@ int tr_env_get_int(char const* key, int default_value)
#else
char const* value = getenv(key);
if (!tr_str_is_empty(value))
if (char const* value = getenv(key); !tr_str_is_empty(value))
{
return atoi(value);
}
@ -1652,8 +1633,7 @@ std::string_view tr_get_mime_type_for_filename(std::string_view filename)
return entry.suffix < suffix;
};
auto const pos = filename.rfind('.');
if (pos != filename.npos)
if (auto const pos = filename.rfind('.'); pos != std::string_view::npos)
{
// make a lowercase copy of the file suffix
filename.remove_prefix(pos + 1);

View File

@ -188,9 +188,6 @@ void* tr_realloc(void* p, size_t size);
/** @brief Portability wrapper around free() in which `nullptr' is a safe argument */
void tr_free(void* p);
/** @brief Free pointers in a nullptr-terminated array (the array itself is not freed) */
void tr_free_ptrv(void* const* p);
/**
* @brief make a newly-allocated copy of a chunk of memory
* @param src the memory to copy

View File

@ -58,7 +58,7 @@ std::optional<int64_t> tr_bencParseInt(std::string_view* benc)
// find the ending delimiter
walk.remove_prefix(1);
auto const pos = walk.find('e');
if (pos == walk.npos)
if (pos == std::string_view::npos)
{
return {};
}
@ -92,7 +92,7 @@ std::optional<std::string_view> tr_bencParseStr(std::string_view* benc)
{
// find the ':' delimiter
auto const colon_pos = benc->find(':');
if (colon_pos == benc->npos)
if (colon_pos == std::string_view::npos)
{
return {};
}

View File

@ -1021,7 +1021,7 @@ static void tr_variantListCopy(tr_variant* target, tr_variant const* src)
int i = 0;
tr_variant const* val = nullptr;
while ((val = tr_variantListChild((tr_variant*)src, i)) != nullptr)
while ((val = tr_variantListChild(const_cast<tr_variant*>(src), i)) != nullptr)
{
if (tr_variantIsBool(val))
{
@ -1098,12 +1098,12 @@ void tr_variantMergeDicts(tr_variant* target, tr_variant const* source)
{
auto key = tr_quark{};
tr_variant* val = nullptr;
if (tr_variantDictChild((tr_variant*)source, i, &key, &val))
if (tr_variantDictChild(const_cast<tr_variant*>(source), i, &key, &val))
{
tr_variant* t = nullptr;
// if types differ, ensure that target will overwrite source
tr_variant* const target_child = tr_variantDictFind(target, key);
auto const* const target_child = tr_variantDictFind(target, key);
if (target_child && !tr_variantIsType(target_child, val->type))
{
tr_variantDictRemove(target, key);

View File

@ -330,13 +330,12 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
// The authority component is preceded by a double slash ("//") and is
// terminated by the next slash ("/"), question mark ("?"), or number
// sign ("#") character, or by the end of the URI.
auto key = "//"sv;
if (tr_strvStartsWith(url, key))
if (auto key = "//"sv; tr_strvStartsWith(url, key))
{
url.remove_prefix(std::size(key));
auto pos = url.find_first_of("/?#");
parsed.authority = url.substr(0, pos);
url = pos == url.npos ? ""sv : url.substr(pos);
url = pos == std::string_view::npos ? ""sv : url.substr(pos);
auto remain = parsed.authority;
parsed.host = tr_strvSep(&remain, ':');
@ -348,7 +347,7 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
// number sign ("#") character, or by the end of the URI.
auto pos = url.find_first_of("?#");
parsed.path = url.substr(0, pos);
url = pos == url.npos ? ""sv : url.substr(pos);
url = pos == std::string_view::npos ? ""sv : url.substr(pos);
// query
if (tr_strvStartsWith(url, '?'))
@ -356,7 +355,7 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
url.remove_prefix(1);
pos = url.find('#');
parsed.query = url.substr(0, pos);
url = pos == url.npos ? ""sv : url.substr(pos);
url = pos == std::string_view::npos ? ""sv : url.substr(pos);
}
// fragment
@ -411,7 +410,7 @@ std::string tr_urlPercentDecode(std::string_view in)
{
auto pos = in.find('%');
out += in.substr(0, pos);
if (pos == in.npos)
if (pos == std::string_view::npos)
{
break;
}

View File

@ -130,14 +130,13 @@ static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* vtask)
static int sockoptfunction(void* vtask, curl_socket_t fd, curlsocktype /*purpose*/)
{
auto* task = static_cast<struct tr_web_task*>(vtask);
auto const isScrape = tr_strvContains(task->url, "scrape"sv);
auto const isAnnounce = tr_strvContains(task->url, "announce"sv);
/* announce and scrape requests have tiny payloads. */
if (isScrape || isAnnounce)
if (auto const is_scrape = tr_strvContains(task->url, "scrape"sv), is_announce = tr_strvContains(task->url, "announce"sv);
is_scrape || is_announce)
{
int const sndbuf = isScrape ? 4096 : 1024;
int const rcvbuf = isScrape ? 4096 : 3072;
int const sndbuf = is_scrape ? 4096 : 1024;
int const rcvbuf = is_scrape ? 4096 : 3072;
/* ignore the sockopt() return values -- these are suggestions
rather than hard requirements & it's OK for them to fail */
(void)setsockopt(fd, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char const*>(&sndbuf), sizeof(sndbuf));
@ -209,9 +208,7 @@ static CURLcode ssl_context_func(CURL* /*curl*/, void* ssl_ctx, void* /*user_dat
static long getTimeoutFromURL(struct tr_web_task const* task)
{
tr_session const* const session = task->session;
if (session == nullptr || session->isClosed)
if (auto const* const session = task->session; session == nullptr || session->isClosed)
{
return 20L;
}