refactor: re-enable some clang-tidy rules (#2498)

This commit is contained in:
Charles Kerr 2022-01-24 13:07:55 -06:00 committed by GitHub
parent 5efec26a3b
commit e83a57efa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 106 additions and 210 deletions

View File

@ -1,139 +1,48 @@
---
# PRs welcome to fix & re-enable any of these explicitly-disabled checks
Checks: >
bugprone-*,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-incorrect-roundings,
-bugprone-narrowing-conversions,
-bugprone-not-null-terminated-result,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-sizeof-expression,
-bugprone-suspicious-include,
cert-*,
-cert-dcl37-c,
-cert-dcl50-cpp,
-cert-dcl51-cpp,
-cert-err33-c,
-cert-err34-c,
-cert-err58-cpp,
-cert-str34-c,
clang-analyzer-core.*,
clang-analyzer-cplusplus.*,
clang-analyzer-security.*,
clang-analyzer-valist.*,
cppcoreguidelines-init-variables,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-virtual-class-destructor,
misc-*,
-misc-misplaced-const,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-raw-string-literal,
-modernize-redundant-void-arg,
-readability-braces-around-statements,
-modernize-use-trailing-return-type,
performance-*,
readability-*,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers,
-readability-named-parameter,
-readability-non-const-parameter,
-readability-qualified-auto,
-readability-redundant-access-specifiers,
-readability-static-accessed-through-instance,
-readability-static-definition-in-anonymous-namespace,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-exception-escape,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-infinite-loop,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-no-escape,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-redundant-branch-condition,
bugprone-signal-handler,
bugprone-sizeof-container,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-stringview-nullptr,
bugprone-suspicious-enum-usage,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-exception-at-new,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cppcoreguidelines-init-variables,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-virtual-class-destructor,
misc-misleading-identifier,
misc-static-assert,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
modernize-use-using,
performance-*,
readability-avoid-const-params-in-decls,
readability-const-return-type,
readability-container-data-pointer,
readability-container-size-empty,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-else-after-return,
readability-function-size,
readability-identifier-naming,
readability-isolate-declaration,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-member-init,
readability-redundant-preprocessor,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-redundant-string-init,
readability-simplify-boolean-expr,
readability-simplify-subscript-expr,
readability-string-compare,
readability-suspicious-call-argument,
readability-uniqueptr-delete-release,
readability-uppercase-literal-suffix,

View File

@ -104,7 +104,7 @@ static auto constexpr TauConnectionTtlSecs = int{ 60 };
using tau_transaction_t = uint32_t;
static tau_transaction_t tau_transaction_new(void)
static tau_transaction_t tau_transaction_new()
{
auto tmp = tau_transaction_t{};
tr_rand_buffer(&tmp, sizeof(tau_transaction_t));

View File

@ -98,7 +98,7 @@ static bool check_openssl_pointer(void const* pointer, char const* file, int lin
****
***/
tr_sha1_ctx_t tr_sha1_init(void)
tr_sha1_ctx_t tr_sha1_init()
{
EVP_MD_CTX* handle = EVP_MD_CTX_create();

View File

@ -32,7 +32,7 @@ static int myQueueLength = 0;
#ifndef _WIN32
/* make null versions of these win32 functions */
static inline bool IsDebuggerPresent(void)
static inline bool IsDebuggerPresent()
{
return false;
}
@ -43,7 +43,7 @@ static inline bool IsDebuggerPresent(void)
****
***/
tr_log_level tr_logGetLevel(void)
tr_log_level tr_logGetLevel()
{
return __tr_message_level;
}
@ -54,7 +54,7 @@ tr_log_level tr_logGetLevel(void)
static std::recursive_mutex message_mutex_;
tr_sys_file_t tr_logGetFile(void)
tr_sys_file_t tr_logGetFile()
{
static bool initialized = false;
static tr_sys_file_t file = TR_BAD_SYS_FILE;
@ -92,12 +92,12 @@ void tr_logSetQueueEnabled(bool isEnabled)
myQueueEnabled = isEnabled;
}
bool tr_logGetQueueEnabled(void)
bool tr_logGetQueueEnabled()
{
return myQueueEnabled;
}
tr_log_message* tr_logGetQueue(void)
tr_log_message* tr_logGetQueue()
{
auto const lock = std::lock_guard(message_mutex_);
@ -143,7 +143,7 @@ char* tr_logGetTimeStr(char* buf, size_t buflen)
return buf;
}
bool tr_logGetDeepEnabled(void)
bool tr_logGetDeepEnabled()
{
static int8_t deepLoggingIsActive = -1;

View File

@ -22,7 +22,7 @@
static auto constexpr LifetimeSecs = uint32_t{ 3600 };
static auto constexpr CommandWaitSecs = time_t{ 8 };
static char const* getKey(void)
static char const* getKey()
{
return _("Port Forwarding (NAT-PMP)");
}
@ -55,7 +55,7 @@ static void logVal(char const* func, int ret)
}
}
struct tr_natpmp* tr_natpmpInit(void)
struct tr_natpmp* tr_natpmpInit()
{
auto* const nat = tr_new0(struct tr_natpmp, 1);
nat->state = TR_NATPMP_DISCOVER;

View File

@ -655,12 +655,16 @@ unsigned char const* tr_globalIPv6(tr_session const* session)
}
if (!have_ipv6)
{
return nullptr; /* No IPv6 address at all. */
}
/* Return the default address. This is useful for checking
for connectivity in general. */
if (session == nullptr)
{
return ipv6;
}
/* We have some sort of address, now make sure that we return
our bound address if non-default. */
@ -668,8 +672,10 @@ unsigned char const* tr_globalIPv6(tr_session const* session)
bool is_default = false;
auto const* ipv6_bindaddr = tr_sessionGetPublicAddress(session, TR_AF_INET6, &is_default);
if (ipv6_bindaddr != nullptr && !is_default)
{
/* Explicitly bound. Return that address. */
memcpy(ipv6, ipv6_bindaddr->addr.addr6.s6_addr, 16);
}
return ipv6;
}

View File

@ -93,7 +93,7 @@ struct tr_datatype
static struct tr_datatype* datatype_pool = nullptr;
static struct tr_datatype* datatype_new(void)
static struct tr_datatype* datatype_new()
{
tr_datatype* ret = nullptr;

View File

@ -223,7 +223,7 @@ std::vector<std::pair<tr_block_index_t, tr_peer*>> ActiveRequests::sentBefore(ti
for (auto& [block, peers_at] : impl_->blocks_)
{
for (auto& sent : peers_at)
for (auto const& sent : peers_at)
{
if (sent.when < when)
{

View File

@ -1713,7 +1713,8 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
for (size_t i = 0; i < n_peers; ++i)
{
auto* peer = peers[i];
auto const* const peer = peers[i];
for (size_t j = 0; j < n_pieces; ++j)
{
if (peer->have.test(j))

View File

@ -2434,8 +2434,8 @@ static void tr_set_compare(
tr_set_func in_both_cb,
void* userData)
{
auto* a = static_cast<uint8_t const*>(va);
auto* b = static_cast<uint8_t const*>(vb);
auto const* a = static_cast<uint8_t const*>(va);
auto const* b = static_cast<uint8_t const*>(vb);
uint8_t const* aend = a + elementSize * aCount;
uint8_t const* bend = b + elementSize * bCount;

View File

@ -100,7 +100,7 @@ using tr_thread_id = DWORD;
using tr_thread_id = pthread_t;
#endif
static tr_thread_id tr_getCurrentThread(void)
static tr_thread_id tr_getCurrentThread()
{
#ifdef _WIN32
return GetCurrentThreadId();
@ -216,7 +216,7 @@ static char* win32_get_known_folder(REFKNOWNFOLDERID folder_id)
#endif
static char const* getHomeDir(void)
static char const* getHomeDir()
{
static char const* home = nullptr;
@ -381,7 +381,7 @@ static std::string getXdgEntryFromUserDirs(std::string_view key)
return val;
}
char const* tr_getDefaultDownloadDir(void)
char const* tr_getDefaultDownloadDir()
{
static char const* user_dir = nullptr;

View File

@ -20,7 +20,7 @@
#include "upnp.h"
#include "utils.h"
static char const* getKey(void)
static char const* getKey()
{
return _("Port Forwarding");
}

View File

@ -34,7 +34,7 @@ struct tr_session_id
time_t expires_at;
};
static char* generate_new_session_id_value(void)
static char* generate_new_session_id_value()
{
char const pool[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
size_t const pool_size = sizeof(pool) - 1;
@ -112,7 +112,7 @@ static void destroy_session_id_lock_file(tr_sys_file_t lock_file, char const* se
}
}
tr_session_id_t tr_session_id_new(void)
tr_session_id_t tr_session_id_new()
{
auto const session_id = tr_new0(struct tr_session_id, 1);

View File

@ -2446,7 +2446,7 @@ int tr_blocklistSetContent(tr_session* session, char const* contentFilename)
bool tr_sessionIsAddressBlocked(tr_session const* session, tr_address const* addr)
{
auto& src = session->blocklists;
auto const& src = session->blocklists;
return std::any_of(
std::begin(src),
std::end(src),
@ -2802,7 +2802,9 @@ int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir)
{
auto const idle_secs = int(difftime(now, std::max(tor->startDate, tor->activityDate)));
if (idle_secs >= stalled_if_idle_for_n_seconds)
{
continue;
}
}
++active_count;

View File

@ -2078,23 +2078,8 @@ uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor)
***** Removing the torrent's local data
****/
static constexpr bool isJunkFile(std::string_view base)
static bool isJunkFile(std::string_view base)
{
auto constexpr Files = std::array<std::string_view, 3>{
".DS_Store"sv,
"Thumbs.db"sv,
"desktop.ini"sv,
};
// TODO(C++20): std::any_of is constexpr in C++20
for (auto const& file : Files)
{
if (file == base)
{
return true;
}
}
#ifdef __APPLE__
// check for resource forks. <http://support.apple.com/kb/TA20578>
if (tr_strvStartsWith(base, "._"sv))
@ -2103,7 +2088,13 @@ static constexpr bool isJunkFile(std::string_view base)
}
#endif
return false;
auto constexpr Files = std::array<std::string_view, 3>{
".DS_Store"sv,
"Thumbs.db"sv,
"desktop.ini"sv,
};
return std::find(std::begin(Files), std::end(Files), base) != std::end(Files);
}
static void removeEmptyFoldersAndJunkFiles(char const* folder)

View File

@ -21,7 +21,7 @@
#include "upnp.h"
#include "utils.h"
static char const* getKey(void)
static char const* getKey()
{
return _("Port Forwarding (UPnP)");
}
@ -58,7 +58,7 @@ struct tr_upnp
***
**/
tr_upnp* tr_upnpInit(void)
tr_upnp* tr_upnpInit()
{
return new tr_upnp();
}

View File

@ -611,7 +611,7 @@ bool tr_str_has_suffix(char const* str, char const* suffix)
*****
****/
uint64_t tr_time_msec(void)
uint64_t tr_time_msec()
{
struct timeval tv;
@ -669,7 +669,7 @@ size_t tr_strlcpy(void* vdst, void const* vsrc, size_t siz)
#else
auto* d = dst;
auto* s = src;
auto const* s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
@ -1555,7 +1555,7 @@ char* tr_env_get_string(char const* key, char const* default_value)
****
***/
void tr_net_init(void)
void tr_net_init()
{
static bool initialized = false;

View File

@ -138,6 +138,8 @@ struct MyHandler : public transmission::benc::Handler
{
}
virtual ~MyHandler() = default;
bool Int64(int64_t value) final
{
if (tr_variant* variant = get_node(); variant != nullptr)

View File

@ -579,9 +579,9 @@ static void jsonStringFunc(tr_variant const* val, void* vdata)
{
try
{
auto* begin8 = std::data(sv);
auto* end8 = begin8 + std::size(sv);
auto* walk8 = begin8;
auto const* const begin8 = std::data(sv);
auto const* const end8 = begin8 + std::size(sv);
auto const* walk8 = begin8;
auto const uch32 = utf8::next(walk8, end8);
outwalk += tr_snprintf(outwalk, outend - outwalk, "\\u%04x", uch32);
sv.remove_prefix(walk8 - begin8 - 1);

View File

@ -26,7 +26,7 @@
static auto constexpr MsecToSleepPerSecondDuringVerify = int{ 100 };
static bool verifyTorrent(tr_torrent* tor, bool* stopFlag)
static bool verifyTorrent(tr_torrent* tor, bool const* stopFlag)
{
auto const begin = tr_time();

View File

@ -173,7 +173,7 @@ void tr_http_escape(struct evbuffer* out, std::string_view str, bool escape_rese
auto constexpr ReservedChars = std::string_view{ "!*'();:@&=+$,/?%#[]" };
auto constexpr UnescapedChars = std::string_view{ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.~" };
for (auto& ch : str)
for (auto const& ch : str)
{
if (tr_strvContains(UnescapedChars, ch) || (tr_strvContains(ReservedChars, ch) && !escape_reserved))
{
@ -191,7 +191,7 @@ void tr_http_escape(std::string& appendme, std::string_view str, bool escape_res
auto constexpr ReservedChars = std::string_view{ "!*'();:@&=+$,/?%#[]" };
auto constexpr UnescapedChars = std::string_view{ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.~" };
for (auto& ch : str)
for (auto const& ch : str)
{
if (tr_strvContains(UnescapedChars, ch) || (!escape_reserved && tr_strvContains(ReservedChars, ch)))
{

View File

@ -14,7 +14,6 @@ Checks: >
-clang-diagnostic-double-promotion,
-clang-diagnostic-exit-time-destructors,
-clang-diagnostic-global-constructors,
-clang-diagnostic-missing-prototypes,
-clang-diagnostic-nonportable-system-include-path,
-clang-diagnostic-old-style-cast,
-clang-diagnostic-shorten-64-to-32,
@ -22,7 +21,6 @@ Checks: >
-clang-diagnostic-sign-conversion,
-clang-diagnostic-switch-enum,
-clang-diagnostic-undefined-reinterpret-cast,
-clang-diagnostic-unused-member-function,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-init-variables,

View File

@ -47,7 +47,6 @@ Checks: >
-hicpp-special-member-functions,
-hicpp-vararg,
misc-*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-concat-nested-namespaces,
@ -57,16 +56,10 @@ Checks: >
performance-*,
-performance-no-int-to-ptr,
readability-*,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers,
-readability-qualified-auto,
-readability-redundant-access-specifiers,
-readability-static-accessed-through-instance,
-readability-suspicious-call-argument
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }

View File

@ -336,7 +336,7 @@ TEST_F(CompletionTest, createPieceBitfield)
EXPECT_TRUE(tr_rand_buffer(std::data(buf), std::size(buf)));
for (uint64_t i = 0; i < block_info.n_pieces; ++i)
{
if (buf[i] % 2)
if ((buf[i] % 2) != 0)
{
completion.addPiece(i);
}

View File

@ -51,7 +51,7 @@ protected:
}
private:
uint64_t fillBufferFromFd(tr_sys_file_t fd, uint64_t bytes_remaining, char* buf, size_t buf_len)
static uint64_t fillBufferFromFd(tr_sys_file_t fd, uint64_t bytes_remaining, char* buf, size_t buf_len)
{
memset(buf, 0, buf_len);
@ -72,7 +72,7 @@ private:
return bytes_remaining;
}
bool filesAreIdentical(char const* fn1, char const* fn2)
static bool filesAreIdentical(char const* fn1, char const* fn2)
{
bool identical = true;

View File

@ -50,7 +50,7 @@ protected:
return test_dir;
}
bool createSymlink(char const* dst_path, char const* src_path, [[maybe_unused]] bool dst_is_dir)
static bool createSymlink(char const* dst_path, char const* src_path, [[maybe_unused]] bool dst_is_dir)
{
#ifndef _WIN32
@ -70,7 +70,7 @@ protected:
#endif
}
bool createHardlink(char const* dst_path, char const* src_path)
static bool createHardlink(char const* dst_path, char const* src_path)
{
#ifndef _WIN32
@ -91,12 +91,12 @@ protected:
#endif
}
void clearPathInfo(tr_sys_path_info* info)
static void clearPathInfo(tr_sys_path_info* info)
{
*info = {};
}
bool pathContainsNoSymlinks(char const* path)
static bool pathContainsNoSymlinks(char const* path)
{
char const* p = path;
@ -135,7 +135,7 @@ protected:
return true;
}
bool validatePermissions([[maybe_unused]] char const* path, [[maybe_unused]] unsigned int permissions)
static bool validatePermissions([[maybe_unused]] char const* path, [[maybe_unused]] unsigned int permissions)
{
#ifndef _WIN32
@ -156,7 +156,7 @@ protected:
char const* output;
};
void testPathXname(XnameTestData const* data, size_t data_size, char* (*func)(std::string_view, tr_error**))
static void testPathXname(XnameTestData const* data, size_t data_size, char* (*func)(std::string_view, tr_error**))
{
for (size_t i = 0; i < data_size; ++i)
{

View File

@ -29,12 +29,12 @@ auto const Options = std::array<tr_option, 8>{
class GetoptTest : public ::testing::Test
{
protected:
void runTest( //
static void runTest( //
int argc,
char const* const* argv,
int expected_n,
int const* expected_c,
char const* const* expected_args) const
char const* const* expected_args)
{
auto n = int{};
tr_optind = 1;

View File

@ -73,7 +73,6 @@ protected:
TEST_F(PeerMgrWishlistTest, doesNotRequestPiecesThatCannotBeRequested)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
@ -92,7 +91,7 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestPiecesThatCannotBeRequested)
}
// we should only get the first piece back
auto spans = wishlist.next(peer_info, 1000);
auto spans = Wishlist::next(peer_info, 1000);
ASSERT_EQ(1, std::size(spans));
EXPECT_EQ(peer_info.block_span_[0].begin, spans[0].begin);
EXPECT_EQ(peer_info.block_span_[0].end, spans[0].end);
@ -101,7 +100,6 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestPiecesThatCannotBeRequested)
TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
@ -126,7 +124,7 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested)
// even if we ask wishlist for more blocks than exist,
// it should omit blocks 1-10 from the return set
auto spans = wishlist.next(peer_info, 1000);
auto spans = Wishlist::next(peer_info, 1000);
auto requested = tr_bitfield(250);
for (auto const& span : spans)
{
@ -140,7 +138,6 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested)
TEST_F(PeerMgrWishlistTest, doesNotRequestTooManyBlocks)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
@ -164,7 +161,7 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestTooManyBlocks)
// but we only ask for 10 blocks,
// so that's how many we should get back
auto const n_wanted = 10;
auto const spans = wishlist.next(peer_info, n_wanted);
auto const spans = Wishlist::next(peer_info, n_wanted);
auto n_got = size_t{};
for (auto const& span : spans)
{
@ -176,7 +173,6 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestTooManyBlocks)
TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
@ -209,7 +205,7 @@ TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
for (int run = 0; run < num_runs; ++run)
{
auto const n_wanted = 10;
auto spans = wishlist.next(peer_info, n_wanted);
auto spans = Wishlist::next(peer_info, n_wanted);
auto n_got = size_t{};
for (auto const& span : spans)
{
@ -227,7 +223,6 @@ TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
@ -256,7 +251,7 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
// even if we ask wishlist to list more blocks than exist,
// those first 150 should be omitted from the return list
auto spans = wishlist.next(peer_info, 1000);
auto spans = Wishlist::next(peer_info, 1000);
auto requested = tr_bitfield(300);
for (auto const& span : spans)
{
@ -269,7 +264,7 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
// BUT during endgame it's OK to request dupes,
// so then we _should_ see the first 150 in the list
peer_info.is_endgame_ = true;
spans = wishlist.next(peer_info, 1000);
spans = Wishlist::next(peer_info, 1000);
requested = tr_bitfield(300);
for (auto const& span : spans)
{
@ -283,7 +278,6 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
{
auto peer_info = MockPeerInfo{};
auto wishlist = Wishlist{};
// setup: three pieces, same size
peer_info.piece_count_ = 3;
@ -320,7 +314,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
auto const num_runs = 1000;
for (int run = 0; run < num_runs; ++run)
{
auto const ranges = wishlist.next(peer_info, 10);
auto const ranges = Wishlist::next(peer_info, 10);
auto requested = tr_bitfield(300);
for (auto const& range : ranges)
{
@ -336,7 +330,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
// those blocks should be next in line.
for (int run = 0; run < num_runs; ++run)
{
auto const ranges = wishlist.next(peer_info, 20);
auto const ranges = Wishlist::next(peer_info, 20);
auto requested = tr_bitfield(300);
for (auto const& range : ranges)
{

View File

@ -67,7 +67,7 @@ protected:
sync();
}
tr_torrent* createTorrentFromBase64Metainfo(tr_ctor* ctor, char const* benc_base64)
static tr_torrent* createTorrentFromBase64Metainfo(tr_ctor* ctor, char const* benc_base64)
{
// create the torrent ctor
auto const benc = tr_base64_decode(benc_base64);
@ -85,7 +85,7 @@ protected:
return tor;
}
bool testFileExistsAndConsistsOfThisString(tr_torrent const* tor, tr_file_index_t file_index, std::string const& str)
static bool testFileExistsAndConsistsOfThisString(tr_torrent const* tor, tr_file_index_t file_index, std::string const& str)
{
auto const str_len = str.size();
auto success = false;
@ -107,7 +107,7 @@ protected:
return success;
}
void expectHaveNone(tr_torrent* tor, uint64_t total_size)
static void expectHaveNone(tr_torrent* tor, uint64_t total_size)
{
auto const* tst = tr_torrentStat(tor);
EXPECT_EQ(TR_STATUS_STOPPED, tst->activity);
@ -118,7 +118,7 @@ protected:
EXPECT_EQ(0, tst->haveValid);
}
int torrentRenameAndWait(tr_torrent* tor, char const* oldpath, char const* newname)
static int torrentRenameAndWait(tr_torrent* tor, char const* oldpath, char const* newname)
{
auto const on_rename_done =
[](tr_torrent* /*tor*/, char const* /*oldpath*/, char const* /*newname*/, int error, void* user_data) noexcept

View File

@ -65,7 +65,7 @@ protected:
std::string self_path_;
void waitForFileToExist(std::string const& path)
static void waitForFileToExist(std::string const& path)
{
auto const test = [path]()
{
@ -193,8 +193,8 @@ TEST_P(SubprocessTest, SpawnAsyncEnv)
{ test_env_key5, test_env_value5 },
};
setenv("FOO", "bar", true); // inherited
setenv("ZOO", "tar", true); // overridden
setenv("FOO", "bar", 1 /*true*/); // inherited
setenv("ZOO", "tar", 1 /*true*/); // overridden
tr_error* error = nullptr;
bool const ret = tr_spawn_async(std::data(args), env, nullptr, &error);

View File

@ -27,7 +27,7 @@ using namespace std::literals;
class VariantTest : public ::testing::Test
{
protected:
std::string stripWhitespace(std::string const& in)
static std::string stripWhitespace(std::string const& in)
{
auto s = in;
s.erase(s.begin(), std::find_if_not(s.begin(), s.end(), ::isspace));
@ -447,7 +447,7 @@ TEST_F(VariantTest, boolAndIntRecast)
tr_variantInitDict(&top, 10);
tr_variantDictAddBool(&top, key1, false);
tr_variantDictAddBool(&top, key2, 0); // NOLINT modernize-use-bool-literals
tr_variantDictAddInt(&top, key3, true);
tr_variantDictAddInt(&top, key3, true); // NOLINT readability-implicit-bool-conversion
tr_variantDictAddInt(&top, key4, 1);
// confirm we can read both bools and ints as bools

View File

@ -89,7 +89,7 @@ protected:
return path;
}
std::string createDir(std::string const& parent_dir, std::string const& name)
static std::string createDir(std::string const& parent_dir, std::string const& name)
{
auto path = parent_dir;
path += TR_PATH_DELIMITER;