mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
fix: coverity warnings (#2229)
* fix: coverity uninitialized member warning Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=204371746\&defectInstanceId\=52288281\&mergedDefectId\=1494442\&eventId\=52288281-41 * fix: coverity uninitialized member warning Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=204371746\&defectInstanceId\=52288281\&mergedDefectId\=1494442\&eventId\=52288281-43 * fix: coverity unchecked return value Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=204371760\&defectInstanceId\=52254984\&mergedDefectId\=1494150 * fix: coverity false nullptr dereference warning Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=204369613\&defectInstanceId\=52254971\&mergedDefectId\=1493396 * fix: coverity unchecked return value Xref: https://scan5.coverity.com/reports.htm\#v48014/p10174/fileInstanceId\=204369625\&defectInstanceId\=52288288\&mergedDefectId\=1491891
This commit is contained in:
parent
74f367c150
commit
dc36787378
5 changed files with 25 additions and 23 deletions
|
@ -1530,7 +1530,12 @@ static void gotNewBlocklist(
|
|||
stream.opaque = (voidpf)Z_NULL;
|
||||
stream.next_in = reinterpret_cast<Bytef const*>(std::data(response));
|
||||
stream.avail_in = std::size(response);
|
||||
inflateInit2(&stream, windowBits);
|
||||
if (inflateInit2(&stream, windowBits) != Z_OK)
|
||||
{
|
||||
// If stream init fails, log an error but keep going forward
|
||||
// since the file may be uncompressed anyway.
|
||||
tr_logAddError("inflateInit2 failed: %s", stream.msg ? stream.msg : "unknown");
|
||||
}
|
||||
|
||||
auto filename = tr_strvPath(configDir, "blocklist.tmp.XXXXXX");
|
||||
tr_sys_file_t const fd = tr_sys_file_open_temp(std::data(filename), &error);
|
||||
|
|
|
@ -753,7 +753,6 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
|
|||
|
||||
tor->session = session;
|
||||
tor->uniqueId = nextUniqueId++;
|
||||
tor->magicNumber = TORRENT_MAGIC_NUMBER;
|
||||
tor->queuePosition = tr_sessionCountTorrents(session);
|
||||
|
||||
tor->dnd_pieces_ = tr_bitfield{ tor->info.pieceCount };
|
||||
|
|
|
@ -357,7 +357,8 @@ public:
|
|||
|
||||
tr_swarm* swarm = nullptr;
|
||||
|
||||
int magicNumber;
|
||||
// TODO: is this actually still needed?
|
||||
int const magicNumber = MagicNumber;
|
||||
|
||||
std::optional<double> verify_progress;
|
||||
|
||||
|
@ -420,7 +421,7 @@ public:
|
|||
uint64_t uploadedCur = 0;
|
||||
uint64_t uploadedPrev = 0;
|
||||
uint64_t corruptCur = 0;
|
||||
uint64_t corruptPrev;
|
||||
uint64_t corruptPrev = 0;
|
||||
|
||||
uint64_t etaDLSpeedCalculatedAt = 0;
|
||||
uint64_t etaULSpeedCalculatedAt = 0;
|
||||
|
@ -490,6 +491,8 @@ public:
|
|||
|
||||
tr_labels_t labels;
|
||||
|
||||
static auto constexpr MagicNumber = int{ 95549 };
|
||||
|
||||
private:
|
||||
mutable std::vector<tr_sha1_digest_t> piece_checksums_;
|
||||
};
|
||||
|
@ -534,14 +537,9 @@ constexpr bool tr_torrentAllowsLPD(tr_torrent const* tor)
|
|||
****
|
||||
***/
|
||||
|
||||
enum
|
||||
{
|
||||
TORRENT_MAGIC_NUMBER = 95549
|
||||
};
|
||||
|
||||
constexpr bool tr_isTorrent(tr_torrent const* tor)
|
||||
{
|
||||
return tor != nullptr && tor->magicNumber == TORRENT_MAGIC_NUMBER && tr_isSession(tor->session);
|
||||
return tor != nullptr && tor->magicNumber == tr_torrent::MagicNumber && tr_isSession(tor->session);
|
||||
}
|
||||
|
||||
/* set a flag indicating that the torrent's .resume file
|
||||
|
|
|
@ -526,8 +526,6 @@ static void jsonStringFunc(tr_variant const* val, void* vdata)
|
|||
|
||||
auto sv = std::string_view{};
|
||||
(void)!tr_variantGetStrView(val, &sv);
|
||||
auto const* it = reinterpret_cast<unsigned char const*>(std::data(sv));
|
||||
auto const* const end = it + std::size(sv);
|
||||
|
||||
evbuffer_reserve_space(data->out, std::size(sv) * 4, vec, 1);
|
||||
auto* out = static_cast<char*>(vec[0].iov_base);
|
||||
|
@ -536,9 +534,9 @@ static void jsonStringFunc(tr_variant const* val, void* vdata)
|
|||
char* outwalk = out;
|
||||
*outwalk++ = '"';
|
||||
|
||||
for (; it != end; ++it)
|
||||
for (; !std::empty(sv); sv.remove_prefix(1))
|
||||
{
|
||||
switch (*it)
|
||||
switch (sv.front())
|
||||
{
|
||||
case '\b':
|
||||
*outwalk++ = '\\';
|
||||
|
@ -576,21 +574,23 @@ static void jsonStringFunc(tr_variant const* val, void* vdata)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (isprint(*it))
|
||||
if (isprint(sv.front()))
|
||||
{
|
||||
*outwalk++ = *it;
|
||||
*outwalk++ = sv.front();
|
||||
}
|
||||
else
|
||||
{
|
||||
UTF8 const* tmp = it;
|
||||
auto const* const begin = reinterpret_cast<UTF8 const*>(std::data(sv));
|
||||
auto const* tmp = begin;
|
||||
auto const* end = tmp + std::size(sv);
|
||||
UTF32 buf[1] = { 0 };
|
||||
UTF32* u32 = buf;
|
||||
ConversionResult result = ConvertUTF8toUTF32(&tmp, end, &u32, buf + 1, {});
|
||||
|
||||
if ((result == conversionOK || result == targetExhausted) && tmp != it)
|
||||
if ((result == conversionOK || result == targetExhausted) && tmp != begin)
|
||||
{
|
||||
outwalk += tr_snprintf(outwalk, outend - outwalk, "\\u%04x", (unsigned int)buf[0]);
|
||||
it = tmp - 1;
|
||||
sv.remove_prefix(tmp - begin - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -276,23 +276,23 @@ static CURL* createEasy(tr_session* s, struct tr_web* web, struct tr_web_task* t
|
|||
tr_address const* addr = tr_sessionGetPublicAddress(s, TR_AF_INET, &is_default_value);
|
||||
if (addr != nullptr && !is_default_value)
|
||||
{
|
||||
curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr));
|
||||
(void)curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr));
|
||||
}
|
||||
|
||||
addr = tr_sessionGetPublicAddress(s, TR_AF_INET6, &is_default_value);
|
||||
if (addr != nullptr && !is_default_value)
|
||||
{
|
||||
curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr));
|
||||
(void)curl_easy_setopt(e, CURLOPT_INTERFACE, tr_address_to_string(addr));
|
||||
}
|
||||
|
||||
if (!std::empty(task->cookies))
|
||||
{
|
||||
curl_easy_setopt(e, CURLOPT_COOKIE, task->cookies.c_str());
|
||||
(void)curl_easy_setopt(e, CURLOPT_COOKIE, task->cookies.c_str());
|
||||
}
|
||||
|
||||
if (web->cookie_filename != nullptr)
|
||||
{
|
||||
curl_easy_setopt(e, CURLOPT_COOKIEFILE, web->cookie_filename);
|
||||
(void)curl_easy_setopt(e, CURLOPT_COOKIEFILE, web->cookie_filename);
|
||||
}
|
||||
|
||||
if (!std::empty(task->range))
|
||||
|
|
Loading…
Reference in a new issue