From d8bdac174d9011f91b2d32dbd11a530ce737866e Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sun, 23 Apr 2023 10:05:37 -0700 Subject: [PATCH] Fix static analysis issues found by PVS-Studio and Coverity --- UEFITool/qhexview5/model/qhexdocument.cpp | 7 ------- UEFITool/qhexview5/model/qhexdocument.h | 1 - UEFITool/qhexview5/model/qhexutils.cpp | 4 ++-- UEFITool/qhexview5/qhexview.cpp | 4 ++-- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/UEFITool/qhexview5/model/qhexdocument.cpp b/UEFITool/qhexview5/model/qhexdocument.cpp index a23002b..a4f1a76 100644 --- a/UEFITool/qhexview5/model/qhexdocument.cpp +++ b/UEFITool/qhexview5/model/qhexdocument.cpp @@ -50,13 +50,6 @@ void QHexDocument::setData(QHexBuffer* buffer) qint64 QHexDocument::length() const { return m_buffer ? m_buffer->length() : 0; } uchar QHexDocument::at(int offset) const { return m_buffer->at(offset); } -QHexDocument* QHexDocument::fromFile(QString filename, QObject* parent) -{ - QFile f(filename); - f.open(QFile::ReadOnly); - return QHexDocument::fromMemory(f.readAll(), parent); -} - void QHexDocument::undo() { m_undostack.undo(); Q_EMIT changed(); } void QHexDocument::redo() { m_undostack.redo(); Q_EMIT changed(); } void QHexDocument::insert(qint64 offset, uchar b) { this->insert(offset, QByteArray(1, b)); } diff --git a/UEFITool/qhexview5/model/qhexdocument.h b/UEFITool/qhexview5/model/qhexdocument.h index 36b06db..bc05b6d 100644 --- a/UEFITool/qhexview5/model/qhexdocument.h +++ b/UEFITool/qhexview5/model/qhexdocument.h @@ -47,7 +47,6 @@ class QHexDocument: public QObject template static QHexDocument* fromMemory(char *data, int size, QObject* parent = nullptr); template static QHexDocument* fromMemory(const QByteArray& ba, QObject* parent = nullptr); static QHexDocument* fromBuffer(QHexBuffer* buffer, QObject* parent = nullptr); - static QHexDocument* fromFile(QString filename, QObject* parent = nullptr); static QHexDocument* create(QObject* parent = nullptr); Q_SIGNALS: diff --git a/UEFITool/qhexview5/model/qhexutils.cpp b/UEFITool/qhexview5/model/qhexutils.cpp index 13125e9..0fab0c9 100644 --- a/UEFITool/qhexview5/model/qhexutils.cpp +++ b/UEFITool/qhexview5/model/qhexutils.cpp @@ -91,7 +91,7 @@ bool match(const QByteArray& data, const QString& pattern) namespace { -unsigned int countBits(uint val) +unsigned int countBits(quint64 val) { if(val <= std::numeric_limits::max()) return QHexFindOptions::Int8; if(val <= std::numeric_limits::max()) return QHexFindOptions::Int16; @@ -257,7 +257,7 @@ QHexPosition offsetToPosition(const QHexOptions* options, qint64 offset) { retur QPair find(const QHexView* hexview, QVariant value, qint64 startoffset, QHexFindMode mode, unsigned int options, QHexFindDirection fd) { - qint64 offset = -1, size = 0; + qint64 offset, size = 0; if(startoffset == -1) startoffset = static_cast(hexview->offset()); if(mode == QHexFindMode::Hex && QHEXVIEW_VARIANT_EQ(value, String)) diff --git a/UEFITool/qhexview5/qhexview.cpp b/UEFITool/qhexview5/qhexview.cpp index 5e970b1..f2820af 100644 --- a/UEFITool/qhexview5/qhexview.cpp +++ b/UEFITool/qhexview5/qhexview.cpp @@ -483,10 +483,10 @@ void QHexView::drawSeparators(QPainter* p) const QLineF l1(this->hexColumnX(), 0, this->hexColumnX(), this->height()); QLineF l2(this->asciiColumnX(), 0, this->asciiColumnX(), this->height()); - if(!m_hexdelegate || (m_hexdelegate && !m_hexdelegate->paintSeparator(p, l1, this))) + if(!m_hexdelegate || !m_hexdelegate->paintSeparator(p, l1, this)) p->drawLine(l1); - if(!m_hexdelegate || (m_hexdelegate && !m_hexdelegate->paintSeparator(p, l2, this))) + if(!m_hexdelegate || !m_hexdelegate->paintSeparator(p, l2, this)) p->drawLine(l2); }