Fix some static analysis warnings

This commit is contained in:
Megamouse 2024-11-27 20:38:07 +01:00
parent 5491fbee5b
commit 657ab4261c
4 changed files with 19 additions and 21 deletions

View File

@ -79,10 +79,13 @@ flow_layout::~flow_layout()
void flow_layout::clear() void flow_layout::clear()
{ {
while (QLayoutItem* item = takeAt(0)) for (QLayoutItem* item : m_item_list)
{ {
delete item->widget(); if (item)
delete item; {
delete item->widget();
delete item;
}
} }
m_item_list.clear(); m_item_list.clear();
m_positions.clear(); m_positions.clear();
@ -185,8 +188,8 @@ int flow_layout::doLayout(const QRect& rect, bool testOnly) const
int x = effectiveRect.x(); int x = effectiveRect.x();
int y = effectiveRect.y(); int y = effectiveRect.y();
int lineHeight = 0; int lineHeight = 0;
int rows = 0; int row_count = 0;
int cols = 0; int col_count = 0;
if (m_dynamic_spacing) if (m_dynamic_spacing)
{ {
@ -259,8 +262,8 @@ int flow_layout::doLayout(const QRect& rect, bool testOnly) const
pos.row = row; pos.row = row;
pos.col = col++; pos.col = col++;
rows = std::max(rows, pos.row + 1); row_count = std::max(row_count, pos.row + 1);
cols = std::max(cols, pos.col + 1); col_count = std::max(col_count, pos.col + 1);
if (!testOnly) if (!testOnly)
item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
@ -269,8 +272,8 @@ int flow_layout::doLayout(const QRect& rect, bool testOnly) const
lineHeight = qMax(lineHeight, item->sizeHint().height()); lineHeight = qMax(lineHeight, item->sizeHint().height());
} }
m_rows = rows; m_rows = row_count;
m_cols = cols; m_cols = col_count;
return y + lineHeight - rect.y() + bottom; return y + lineHeight - rect.y() + bottom;
} }

View File

@ -11,16 +11,11 @@ struct gui_save
gui_save() gui_save()
{ {
key = "";
name = "";
def = QVariant();
} }
gui_save(const QString& k, const QString& n, const QVariant& d) gui_save(const QString& k, const QString& n, const QVariant& d)
: key(k), name(n), def(d)
{ {
key = k;
name = n;
def = d;
} }
bool operator==(const gui_save& rhs) const noexcept bool operator==(const gui_save& rhs) const noexcept

View File

@ -14,9 +14,9 @@ class user_account
public: public:
explicit user_account(const std::string& user_id = "00000001"); explicit user_account(const std::string& user_id = "00000001");
std::string GetUserId() const { return m_user_id; } const std::string& GetUserId() const { return m_user_id; }
std::string GetUserDir() const { return m_user_dir; } const std::string& GetUserDir() const { return m_user_dir; }
std::string GetUsername() const { return m_username; } const std::string& GetUsername() const { return m_username; }
static std::map<u32, user_account> GetUserAccounts(const std::string& base_dir); static std::map<u32, user_account> GetUserAccounts(const std::string& base_dir);

View File

@ -989,14 +989,14 @@ template <typename To, typename From> requires (std::is_integral_v<decltype(std:
constexpr bool is_from_signed = std::is_signed_v<CommonFrom>; constexpr bool is_from_signed = std::is_signed_v<CommonFrom>;
constexpr bool is_to_signed = std::is_signed_v<CommonTo>; constexpr bool is_to_signed = std::is_signed_v<CommonTo>;
constexpr auto from_mask = is_from_signed > is_to_signed ? UnFrom{umax} >> 1 : UnFrom{umax}; constexpr auto from_mask = (is_from_signed && !is_to_signed) ? UnFrom{umax} >> 1 : UnFrom{umax};
constexpr auto to_mask = is_to_signed > is_from_signed ? UnTo{umax} >> 1 : UnTo{umax}; constexpr auto to_mask = (is_to_signed && !is_from_signed) ? UnTo{umax} >> 1 : UnTo{umax};
constexpr auto mask = ~(from_mask & to_mask); constexpr auto mask = ~(from_mask & to_mask);
// Signed to unsigned always require test // Signed to unsigned always require test
// Otherwise, this is bit-wise narrowing or conversion between types of different signedness of the same size // Otherwise, this is bit-wise narrowing or conversion between types of different signedness of the same size
if constexpr (is_from_signed > is_to_signed || to_mask < from_mask) if constexpr ((is_from_signed && !is_to_signed) || to_mask < from_mask)
{ {
// Try to optimize test if both are of the same signedness // Try to optimize test if both are of the same signedness
if (is_from_signed != is_to_signed ? !!(value & mask) : static_cast<CommonTo>(value) != value) [[unlikely]] if (is_from_signed != is_to_signed ? !!(value & mask) : static_cast<CommonTo>(value) != value) [[unlikely]]