fix: coverity warnings (#2186)

* fix: silence check_return warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924665\&defectInstanceId\=52245209\&mergedDefectId\=1494152

* fix: silence check_return warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924692\&defectInstanceId\=52245241\&mergedDefectId\=1493826

* fix: silence check_return warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924667\&defectInstanceId\=52245260\&mergedDefectId\=1493825

* fix: silence nullptr dereference warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924667\&defectInstanceId\=52245260\&mergedDefectId\=1493825

* fix: uninitialized variable in rpc-server z_stream

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924665\&defectInstanceId\=52245249\&mergedDefectId\=1494151

* fix: silence check_return warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924665\&defectInstanceId\=52245261\&mergedDefectId\=1492904

* fix: silence nullptr dereference warning

https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924689\&defectInstanceId\=52245236\&mergedDefectId\=1492890

* fix: silence unchecked return value warning

Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=203924666\&defectInstanceId\=52245259\&mergedDefectId\=1491888
This commit is contained in:
Charles Kerr 2021-11-17 15:56:50 -06:00 committed by GitHub
parent 1ba81938bf
commit ec94c90da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 10 deletions

View File

@ -220,7 +220,7 @@ std::vector<std::string> gtr_pref_strv_get(tr_quark const key)
std::string gtr_pref_string_get(tr_quark const key)
{
auto sv = std::string_view{};
tr_variantDictFindStrView(getPrefs(), key, &sv);
(void)tr_variantDictFindStrView(getPrefs(), key, &sv);
return std::string{ sv };
}

View File

@ -287,7 +287,13 @@ static void add_response(struct evhttp_request* req, tr_rpc_server* server, stru
#else
int const compressionLevel = Z_BEST_COMPRESSION;
#endif
deflateInit2(&server->stream, compressionLevel, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
// "windowBits can also be greater than 15 for optional gzip encoding.
// Add 16 to windowBits to write a simple gzip header and trailer
// around the compressed data instead of a zlib wrapper."
if (Z_OK != deflateInit2(&server->stream, compressionLevel, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY))
{
tr_logAddNamedDbg(MY_NAME, "deflateInit2 failed: %s", server->stream.msg);
}
}
server->stream.next_in = static_cast<Bytef*>(content_ptr);

View File

@ -317,7 +317,7 @@ static char const* torrentRemove(
tr_rpc_idle_data* /*idle_data*/)
{
auto delete_flag = bool{ false };
tr_variantDictFindBool(args_in, TR_KEY_delete_local_data, &delete_flag);
(void)tr_variantDictFindBool(args_in, TR_KEY_delete_local_data, &delete_flag);
tr_rpc_callback_type type = delete_flag ? TR_RPC_TORRENT_TRASHING : TR_RPC_TORRENT_REMOVING;
@ -1386,7 +1386,7 @@ static char const* torrentSetLocation(
}
auto move = bool{};
tr_variantDictFindBool(args_in, TR_KEY_move, &move);
(void)tr_variantDictFindBool(args_in, TR_KEY_move, &move);
for (auto* tor : getTorrents(session, args_in))
{
@ -1515,7 +1515,7 @@ static void gotNewBlocklist(
}
else /* successfully fetched the blocklist... */
{
z_stream stream;
auto stream = z_stream{};
char const* configDir = tr_sessionGetConfigDir(session);
size_t const buflen = 1024 * 128; /* 128 KiB buffer */
auto* const buf = static_cast<uint8_t*>(tr_malloc(buflen));

View File

@ -843,7 +843,7 @@ static void sessionSetImpl(void* vdata)
}
sv = ""sv;
tr_variantDictFindStrView(settings, TR_KEY_peer_congestion_algorithm, &sv);
(void)tr_variantDictFindStrView(settings, TR_KEY_peer_congestion_algorithm, &sv);
session->setPeerCongestionAlgorithm(sv);
if (tr_variantDictFindBool(settings, TR_KEY_blocklist_enabled, &boolVal))

View File

@ -37,11 +37,20 @@ TEST(Metainfo, magnetLink)
auto const parse_result = tr_torrentParse(ctor, &inf);
EXPECT_EQ(TR_PARSE_OK, parse_result);
EXPECT_EQ(0, inf.fileCount); // because it's a magnet link
EXPECT_EQ(2, inf.trackerCount);
EXPECT_STREQ("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
EXPECT_STREQ("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
ASSERT_EQ(2, inf.trackerCount);
if (inf.trackerCount >= 1)
{
EXPECT_STREQ("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
}
if (inf.trackerCount >= 2)
{
EXPECT_STREQ("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
}
EXPECT_EQ(1, inf.webseedCount);
EXPECT_STREQ("http://transmissionbt.com", inf.webseeds[0]);
if (inf.webseedCount >= 1)
{
EXPECT_STREQ("http://transmissionbt.com", inf.webseeds[0]);
}
auto* const link = tr_torrentInfoGetMagnetLink(&inf);
EXPECT_STREQ(MagnetLink, link);

View File

@ -139,24 +139,29 @@ TEST_P(SubprocessTest, SpawnAsyncArgs)
buffer[0] = '\0';
EXPECT_TRUE(tr_sys_file_read_line(fd, buffer.data(), buffer.size(), nullptr));
buffer.back() = '\0';
EXPECT_EQ(test_arg1, buffer.data());
buffer[0] = '\0';
EXPECT_TRUE(tr_sys_file_read_line(fd, buffer.data(), buffer.size(), nullptr));
buffer.back() = '\0';
EXPECT_EQ(test_arg2, buffer.data());
buffer[0] = '\0';
EXPECT_TRUE(tr_sys_file_read_line(fd, buffer.data(), buffer.size(), nullptr));
buffer.back() = '\0';
EXPECT_EQ(test_arg3, buffer.data());
if (allow_batch_metachars)
{
buffer[0] = '\0';
EXPECT_TRUE(tr_sys_file_read_line(fd, buffer.data(), buffer.size(), nullptr));
buffer.back() = '\0';
EXPECT_EQ(test_arg4, buffer.data());
}
EXPECT_FALSE(tr_sys_file_read_line(fd, buffer.data(), buffer.size(), nullptr));
buffer.back() = '\0';
tr_sys_file_close(fd, nullptr);
}