refactor: fix some msvc compiler warnings (#2185)

* refactor: use if-constexpr to silence C4127 warning

* chore: fix C4706 assignment-within-conditional-expression warning

* chore: fix int-widened-to-uint64 warning in tests
This commit is contained in:
Charles Kerr 2021-11-16 13:25:30 -06:00 committed by GitHub
parent 0fba476917
commit 60b802a22b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -1757,7 +1757,8 @@ tr_tracker_stat* tr_announcerStats(tr_torrent const* torrent, int* setmeTrackerC
}
else
{
if ((st->hasScraped = tier->lastScrapeTime != 0))
st->hasScraped = tier->lastScrapeTime;
if (st->hasScraped != 0)
{
st->lastScrapeTime = tier->lastScrapeTime;
st->lastScrapeSucceeded = tier->lastScrapeSucceeded;
@ -1785,7 +1786,8 @@ tr_tracker_stat* tr_announcerStats(tr_torrent const* torrent, int* setmeTrackerC
st->lastAnnounceStartTime = tier->lastAnnounceStartTime;
if ((st->hasAnnounced = tier->lastAnnounceTime != 0))
st->hasAnnounced = tier->lastAnnounceTime;
if (st->hasAnnounced != 0)
{
st->lastAnnounceTime = tier->lastAnnounceTime;
tr_strlcpy(st->lastAnnounceResult, tier->lastAnnounceStr, sizeof(st->lastAnnounceResult));

View File

@ -306,7 +306,7 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
}
/* file size should be able to fit into size_t */
if (sizeof(info.size) > sizeof(*size))
if constexpr (sizeof(info.size) > sizeof(*size))
{
TR_ASSERT(info.size <= SIZE_MAX);
}

View File

@ -212,7 +212,7 @@ TEST_F(RenameTest, singleFilenameTorrent)
// (while it's renamed: confirm that the .resume file remembers the changes)
tr_torrentSaveResume(tor);
sync();
loaded = tr_torrentLoadResume(tor, ~0, ctor, nullptr);
loaded = tr_torrentLoadResume(tor, ~0ULL, ctor, nullptr);
EXPECT_STREQ("foobar", tr_torrentName(tor));
EXPECT_NE(decltype(loaded){ 0 }, (loaded & TR_FR_NAME));
@ -331,7 +331,7 @@ TEST_F(RenameTest, multifileTorrent)
// this is a bit dodgy code-wise, but let's make sure the .resume file got the name
tr_free(files[1].name);
tor->info.files[1].name = tr_strdup("gabba gabba hey");
auto const loaded = tr_torrentLoadResume(tor, ~0, ctor, nullptr);
auto const loaded = tr_torrentLoadResume(tor, ~0ULL, ctor, nullptr);
EXPECT_NE(decltype(loaded){ 0 }, (loaded & TR_FR_FILENAMES));
EXPECT_EQ(expected_files[0], files[0].name);
EXPECT_STREQ("Felidae/Felinae/Felis/placeholder/Kyphi", files[1].name);