Address various cppcheck warnings
MODIFY
external/fancytabbar/fancytab.cpp
external/fancytabbar/fancytab.cpp
#include <QDebug>
-FancyTab::FancyTab(QIcon &icon, QString text)
-{
+FancyTab::FancyTab(const QIcon& icon, QString text) {
m_icon = icon;
m_text = text;
}

MODIFY
external/fancytabbar/fancytab.h
external/fancytabbar/fancytab.h
#ifndef FANCYTAB_H
#define FANCYTAB_H
-#include <QString>
#include <QIcon>
+#include <QString>
/*!
* \brief The FancyTab class is more like struct than class. It has constructor
* to set tab icon and tab text and the the icon and tab are accesseble
* directly.
*/
-class FancyTab
-{
+class FancyTab {
public:
- FancyTab(QIcon &icon, QString text);
+ FancyTab(const QIcon& icon, QString text);
QString m_text;
QIcon m_icon;

MODIFY
src/assembler/expreval.cpp
src/assembler/expreval.cpp
@@ -30,7 +30,7 @@ struct Nothing : Printable {
};
struct Literal : Printable {
- Literal(QString _v) : v(_v) {}
+ explicit Literal(const QString& _v) : v(_v) {}
QString v;
void print(std::ostream& str) const override;
};
@@ -191,7 +191,7 @@ ExprRes parseLeft(const QString& s, int& pos, int& depth) {
return {*err};
}
- auto& res = std::get<std::shared_ptr<Expr>>(left);
+ const auto& res = std::get<std::shared_ptr<Expr>>(left);
if (pos < s.length()) {
auto& ch = s.at(pos);
pos++;

MODIFY
src/cachesim/cachesim.cpp
src/cachesim/cachesim.cpp
@@ -125,12 +125,11 @@ std::pair<unsigned, CacheSim::CacheWay*> CacheSim::locateEvictionWay(const Cache
}
// If there is an invalid cache line, select that
- for (auto& way : cacheLine) {
- if (!way.second.valid) {
- ew.first = way.first;
- ew.second = &way.second;
- break;
- }
+ auto it =
+ std::find_if(cacheLine.begin(), cacheLine.end(), [=](const auto& way) { return !way.second.valid; });
+ if (it != cacheLine.end()) {
+ ew.first = it->first;
+ ew.second = &it->second;
}
if (ew.second == nullptr) {
// Else, Find LRU way

MODIFY
src/console.cpp
src/console.cpp
@@ -64,7 +64,6 @@ void Console::backspace() {
}
void Console::keyPressEvent(QKeyEvent* e) {
- bool backspacedBuffer = false;
switch (e->key()) {
case Qt::Key_Left:
case Qt::Key_Right:
@@ -74,6 +73,7 @@ void Console::keyPressEvent(QKeyEvent* e) {
break;
default:
if (!e->text().isEmpty()) {
+ bool backspacedBuffer = false;
const QString text = e->text();
// Buffer managing
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {

MODIFY
src/io/ioswitches.cpp
src/io/ioswitches.cpp
@@ -84,17 +84,14 @@ void ToggleButton::paintEvent(QPaintEvent*) {
qreal thumbOpacity = 1.0;
QBrush trackBrush;
QBrush thumbBrush;
- QColor textColor;
if (this->isEnabled()) {
trackBrush = mTrackColor[check];
thumbBrush = mThumbColor[check];
- textColor = mTextColor[check];
} else {
trackOpacity *= 0.8;
trackBrush = this->palette().shadow();
thumbBrush = this->palette().mid();
- textColor = this->palette().shadow().color();
}
p.setBrush(trackBrush);
@@ -190,11 +187,9 @@ void IOSwitches::updateSwitches() {
}
uint32_t IOSwitches::ioRead(uint32_t, unsigned) {
- uint32_t value = 0;
- for (const auto& sw : m_switches) {
- value |= (sw.second.second->isChecked()) << sw.first;
- }
- return value;
+ return std::accumulate(m_switches.begin(), m_switches.end(), 0, [=](uint32_t acc, const auto& sw) {
+ return acc | (sw.second.second->isChecked()) << sw.first;
+ });
}
void IOSwitches::ioWrite(uint32_t, uint32_t, unsigned) {

MODIFY
test/tst_cosimulate.cpp
test/tst_cosimulate.cpp
@@ -57,7 +57,7 @@ class tst_Cosimulate : public QObject {
Q_OBJECT
public:
- explicit tst_Cosimulate(){};
+ explicit tst_Cosimulate() {}
private:
void cosimulate(const ProcessorID& id, const QStringList& extensions);

Address various cppcheck warnings