mirror of
https://github.com/transmission/transmission.git
synced 2025-12-19 18:08:31 +00:00
fix: coverity warnings, sonarcloud code smells (#4232)
This commit is contained in:
@@ -308,13 +308,30 @@ void Session::Impl::dec_busy()
|
||||
namespace
|
||||
{
|
||||
|
||||
bool is_valid_eta(int t)
|
||||
template<typename T>
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
constexpr int compare_generic(T const& a, T const& b)
|
||||
{
|
||||
if (a < b)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a > b)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr bool is_valid_eta(time_t t)
|
||||
{
|
||||
return t != TR_ETA_NOT_AVAIL && t != TR_ETA_UNKNOWN;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
int compare_eta(int a, int b)
|
||||
constexpr int compare_eta(time_t a, time_t b)
|
||||
{
|
||||
bool const a_valid = is_valid_eta(a);
|
||||
bool const b_valid = is_valid_eta(b);
|
||||
@@ -334,39 +351,28 @@ int compare_eta(int a, int b)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return a < b ? 1 : -1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
int compare_generic(T&& a, T&& b)
|
||||
{
|
||||
return a < b ? -1 : (a > b ? 1 : 0);
|
||||
return -compare_generic(a, b);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
int compare_ratio(double a, double b)
|
||||
constexpr int compare_ratio(double a, double b)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF)
|
||||
if (static_cast<int>(a) == TR_RATIO_INF && static_cast<int>(b) == TR_RATIO_INF)
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
else if ((int)a == TR_RATIO_INF)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
else if ((int)b == TR_RATIO_INF)
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = compare_generic(a, b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
if (static_cast<int>(a) == TR_RATIO_INF)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (static_cast<int>(b) == TR_RATIO_INF)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return compare_generic(a, b);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
|
||||
Reference in New Issue
Block a user