From 14ec74239b52288a583ad1cb7b3303d3c31148cd Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 1 Dec 2020 20:37:43 +0000 Subject: [PATCH] fix some static analyzer warnings upstream commit: https://github.com/qt/qtbase/commit/8936918a651ac297c91bfd285995993b306347ab Signed-off-by: Ivailo Monev --- src/core/io/qfilesystemengine.cpp | 4 ---- src/core/io/qresource.cpp | 15 +++++---------- src/core/io/qurl.cpp | 4 +--- src/core/kernel/qcoreapplication.cpp | 4 ---- src/core/tools/qlocale.cpp | 18 +++++++++++------- src/core/tools/qstring.cpp | 8 ++++---- src/gui/dialogs/qcolordialog.cpp | 3 +-- src/gui/kernel/qshortcut.cpp | 2 +- src/gui/painting/qbezier.cpp | 2 -- src/gui/painting/qdrawutil.cpp | 4 ++-- src/gui/painting/qpaintengine_raster.cpp | 1 - src/gui/painting/qtextureglyphcache.cpp | 4 ---- src/gui/styles/qcommonstyle.cpp | 3 +-- src/gui/text/qfontsubset.cpp | 2 +- src/gui/text/qtextengine.cpp | 8 ++------ src/network/kernel/qauthenticator.cpp | 1 - src/test/qtestlog.cpp | 2 +- src/tools/moc/moc.cpp | 3 ++- src/tools/uic/cpp/cppwriteicondata.cpp | 4 +--- 19 files changed, 33 insertions(+), 59 deletions(-) diff --git a/src/core/io/qfilesystemengine.cpp b/src/core/io/qfilesystemengine.cpp index 4744f80f3..77049693c 100644 --- a/src/core/io/qfilesystemengine.cpp +++ b/src/core/io/qfilesystemengine.cpp @@ -36,10 +36,6 @@ #include "qset.h" #include "qabstractfileengine_p.h" -#ifndef QT_BOOTSTRAPPED -# include "qresource_p.h" -#endif - QT_BEGIN_NAMESPACE //these unix functions are in this file, because they were shared by symbian port diff --git a/src/core/io/qresource.cpp b/src/core/io/qresource.cpp index 82acb58e6..47eaeb7b9 100644 --- a/src/core/io/qresource.cpp +++ b/src/core/io/qresource.cpp @@ -791,15 +791,12 @@ public: virtual ResourceRootType type() const { return Resource_Buffer; } bool registerSelf(const uchar *b) { - //setup the data now - int offset = 0; - //magic number - if(b[offset+0] != 'q' || b[offset+1] != 'r' || - b[offset+2] != 'e' || b[offset+3] != 's') { + if(b[0] != 'q' || b[1] != 'r' || b[2] != 'e' || b[3] != 's') { return false; } - offset += 4; + //setup the data now + int offset = 4; const int version = (b[offset+0] << 24) + (b[offset+1] << 16) + (b[offset+2] << 8) + (b[offset+3] << 0); @@ -815,7 +812,6 @@ public: const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + (b[offset+2] << 8) + (b[offset+3] << 0); - offset += 4; if(version == Q_RCC_OUTPUT_REVISION) { buffer = b; @@ -842,11 +838,10 @@ public: bool registerSelf(const QString &f) { QFile file(f); if (file.open(QIODevice::ReadOnly)) { - unsigned int data_len = file.size(); + qint64 data_len = file.size(); uchar *data = new uchar[data_len]; - if (data_len != (uint)file.read((char*)data, data_len)) { + if (data_len != file.read((char*)data, data_len)) { delete [] data; - data_len = 0; return false; } else if (QDynamicBufferResourceRoot::registerSelf(data)) { fileName = f; diff --git a/src/core/io/qurl.cpp b/src/core/io/qurl.cpp index 59c1a1587..925d1fdfd 100644 --- a/src/core/io/qurl.cpp +++ b/src/core/io/qurl.cpp @@ -681,11 +681,9 @@ static bool QT_FASTCALL _IPv6Address(const char **ptr) int canBeCase = -1; bool ls32WasRead = false; - const char *tmpBackup = *ptr; - // count the number of (h16 ":") on the right of :: for (;;) { - tmpBackup = *ptr; + const char *tmpBackup = *ptr; if (!_h16(ptr)) { if (!_ls32(ptr)) { if (rightHexColons != 0) { diff --git a/src/core/kernel/qcoreapplication.cpp b/src/core/kernel/qcoreapplication.cpp index c8e80aece..59b96c6e2 100644 --- a/src/core/kernel/qcoreapplication.cpp +++ b/src/core/kernel/qcoreapplication.cpp @@ -1787,10 +1787,6 @@ void QCoreApplication::setLibraryPaths(const QStringList &paths) is \c INSTALL/plugins, where \c INSTALL is the directory where Qt was installed. - In Symbian this function is only useful for adding paths for - finding Qt extension plugin stubs, since the OS can only - load libraries from the \c{/sys/bin} directory. - \sa removeLibraryPath(), libraryPaths(), setLibraryPaths() */ void QCoreApplication::addLibraryPath(const QString &path) diff --git a/src/core/tools/qlocale.cpp b/src/core/tools/qlocale.cpp index 64536cbcc..4de891e1e 100644 --- a/src/core/tools/qlocale.cpp +++ b/src/core/tools/qlocale.cpp @@ -472,15 +472,19 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) static quint16 localePrivateIndex(const QLocalePrivate *p) { + if (Q_LIKELY(p)) { #ifndef QT_NO_SYSTEMLOCALE - if (p && p == system_lp) - return systemLocaleIndex; + if (p == system_lp) { + return systemLocaleIndex; + } #endif - for (qint16 i = 0; i < localeTblSize; i++) { - if (p->m_language == localeTbl[i].m_language - && p->m_country == localeTbl[i].m_country - && p->m_script == localeTbl[i].m_script) - return i; + for (qint16 i = 0; i < localeTblSize; i++) { + if (p->m_language == localeTbl[i].m_language + && p->m_country == localeTbl[i].m_country + && p->m_script == localeTbl[i].m_script) { + return i; + } + } } return 0; } diff --git a/src/core/tools/qstring.cpp b/src/core/tools/qstring.cpp index 5e1b86551..fa2a62abb 100644 --- a/src/core/tools/qstring.cpp +++ b/src/core/tools/qstring.cpp @@ -1249,11 +1249,11 @@ QString& QString::insert(int i, const QChar *unicode, int size) const ushort *s = (const ushort *)unicode; if (s >= d->data && s < d->data + d->alloc) { // Part of me - take a copy - ushort *tmp = static_cast(malloc(size * sizeof(QChar))); + QChar *tmp = static_cast(::malloc(size * sizeof(QChar))); Q_CHECK_PTR(tmp); - memcpy(tmp, s, size * sizeof(QChar)); - insert(i, reinterpret_cast(tmp), size); - free(tmp); + ::memcpy(tmp, s, size * sizeof(QChar)); + insert(i, tmp, size); + ::free(tmp); return *this; } diff --git a/src/gui/dialogs/qcolordialog.cpp b/src/gui/dialogs/qcolordialog.cpp index 792500f2d..b4318d7a3 100644 --- a/src/gui/dialogs/qcolordialog.cpp +++ b/src/gui/dialogs/qcolordialog.cpp @@ -227,7 +227,7 @@ QSize QWellArray::sizeHint() const void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect) { - int b = 3; //margin + static const int b = 3; //margin const QPalette & g = palette(); QStyleOptionFrame opt; @@ -238,7 +238,6 @@ void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect) opt.palette = g; opt.state = QStyle::State_Enabled | QStyle::State_Sunken; style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this); - b += dfw; if ((row == curRow) && (col == curCol)) { if (hasFocus()) { diff --git a/src/gui/kernel/qshortcut.cpp b/src/gui/kernel/qshortcut.cpp index e93989342..c94da202a 100644 --- a/src/gui/kernel/qshortcut.cpp +++ b/src/gui/kernel/qshortcut.cpp @@ -380,7 +380,7 @@ bool QShortcut::event(QEvent *e) if (QWhatsThis::inWhatsThisMode()) { QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); handled = true; - } else + } #endif if (se->isAmbiguous()) emit activatedAmbiguously(); diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index 382770b71..1bc30bb65 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -477,10 +477,8 @@ qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const if (yt < y) { t0 = t; - py0 = yt; } else { t1 = t; - py1 = yt; } dt = lt - t; lt = t; diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index 4def62338..31c534b0a 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -788,8 +788,8 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin yTarget[rows - 1] = targetCenterBottom; yTarget[rows] = targetRect.top() + targetRect.height(); - qreal dx = targetCenterWidth; - qreal dy = targetCenterHeight; + qreal dx = 0; + qreal dy = 0; switch (rules.horizontal) { case Qt::StretchTile: diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 71837ec24..082d5d469 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -2640,7 +2640,6 @@ void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSp } if (n) { fg->blend(n, spans, fg); - n = 0; } } diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index 9e9073fff..992fc5178 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -132,7 +132,6 @@ bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const } QHash listItemCoordinates; - int rowHeight = 0; QFontEngine::GlyphFormat format; switch (m_type) { @@ -189,13 +188,10 @@ bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const -metrics.y.truncate() }; // baseline for horizontal scripts listItemCoordinates.insert(key, c); - rowHeight = qMax(rowHeight, glyph_height); } if (listItemCoordinates.isEmpty()) return true; - rowHeight += margin * 2; - if (m_w == 0) { if (fontEngine->maxCharWidth() <= QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH) m_w = QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH; diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 412ef744c..4c2efca70 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -4539,7 +4539,7 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, if (const QStyleOptionMenuItem *mi = qstyleoption_cast(opt)) { bool checkable = mi->menuHasCheckableItems; int maxpmw = mi->maxIconWidth; - int w = sz.width(), h = sz.height(); + int w = sz.width(), h = 0; if (mi->menuItemType == QStyleOptionMenuItem::Separator) { w = 10; h = 2; @@ -4714,7 +4714,6 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_LineEdit_PasswordCharacter: { const QFontMetrics &fm = opt ? opt->fontMetrics : (widget ? widget->fontMetrics() : QFontMetrics(QFont())); - ret = 0; if (fm.inFont(QChar(0x25CF))) { ret = 0x25CF; } else if (fm.inFont(QChar(0x2022))) { diff --git a/src/gui/text/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp index 202401d69..23c0e2303 100644 --- a/src/gui/text/qfontsubset.cpp +++ b/src/gui/text/qfontsubset.cpp @@ -973,7 +973,7 @@ static void convertPath(const QPainterPath &path, QList *points, QLis // see if we can optimize out the last onCurve point int mx = (points->at(points->size() - 2).x + base[2].x) >> 1; int my = (points->at(points->size() - 2).y + base[2].y) >> 1; - if (qAbs(mx - base[3].x) <= split_limit && qAbs(my = base[3].y) <= split_limit) + if (qAbs(mx - base[3].x) <= split_limit && qAbs(my - base[3].y) <= split_limit) points->takeLast(); try_reduce = false; } diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index f3968999b..91a74a4cd 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -434,8 +434,6 @@ static bool bidiItemize(QTextEngine *engine, QScriptAnalysis *analysis, QBidiCon status.last = control.direction(); if (control.override) dir = control.direction(); - else - dir = QChar::DirON; status.lastStrong = control.direction(); } break; @@ -593,8 +591,7 @@ static bool bidiItemize(QTextEngine *engine, QScriptAnalysis *analysis, QBidiCon // neutrals go to R eor = current - 1; appendItems(analysis, sor, eor, control, dir); - dir = QChar::DirON; status.eor = QChar::DirEN; - dir = QChar::DirAN; + dir = QChar::DirAN; status.eor = QChar::DirEN; } else if(status.eor == QChar::DirL || (status.eor == QChar::DirEN && status.lastStrong == QChar::DirL)) { @@ -607,8 +604,7 @@ static bool bidiItemize(QTextEngine *engine, QScriptAnalysis *analysis, QBidiCon eor = current - 1; dir = QChar::DirR; appendItems(analysis, sor, eor, control, dir); - dir = QChar::DirON; status.eor = QChar::DirON; - dir = QChar::DirAN; + dir = QChar::DirAN; status.eor = QChar::DirON; } else { eor = current; status.eor = dirCurrent; } diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 4937e9310..6558dccec 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -491,7 +491,6 @@ QHash QAuthenticatorPrivate::parseDigestAuthenticationCh ++d; if (d >= end) break; - start = d; QByteArray value; while (d < end) { bool backslash = false; diff --git a/src/test/qtestlog.cpp b/src/test/qtestlog.cpp index c00673d39..7e95c966b 100644 --- a/src/test/qtestlog.cpp +++ b/src/test/qtestlog.cpp @@ -90,7 +90,7 @@ namespace QTest { IgnoreResultList *last = 0; IgnoreResultList *list = ignoreResultList; while (list) { - if (list->type == type && strcmp(msg, list->msg) == 0) { + if (list->type == type && qstrcmp(msg, list->msg) == 0) { // remove the item from the list if (last) last->next = list->next; diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 08df63e08..c0804f495 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -601,7 +601,8 @@ void Moc::parse() if (inNamespace(&namespaceList.at(i))) def.qualified.prepend(namespaceList.at(i).name + "::"); while (inClass(&def) && hasNext()) { - switch ((t = next())) { + t = next(); + switch (t) { case PRIVATE: access = FunctionDef::Private; if (test(Q_SIGNALS_TOKEN)) diff --git a/src/tools/uic/cpp/cppwriteicondata.cpp b/src/tools/uic/cpp/cppwriteicondata.cpp index fbbb90ee6..35722ba91 100644 --- a/src/tools/uic/cpp/cppwriteicondata.cpp +++ b/src/tools/uic/cpp/cppwriteicondata.cpp @@ -80,12 +80,10 @@ void WriteIconData::writeImage(QTextStream &output, const QString &indent, const { QString img = image->attributeName() + QLatin1String("_data"); QString data = image->elementData()->text(); - QString fmt = image->elementData()->attributeFormat(); - int size = image->elementData()->attributeLength(); output << indent << "static const unsigned char " << img << "[] = { \n"; output << indent; - int a ; + int a; for (a = 0; a < (int) (data.length()/2)-1; a++) { output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << ','; if (a % 12 == 11) -- 2.11.0