OSDN Git Service

fix some static analyzer warnings
authorIvailo Monev <xakepa10@gmail.com>
Tue, 1 Dec 2020 20:37:43 +0000 (20:37 +0000)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 1 Dec 2020 21:44:39 +0000 (21:44 +0000)
upstream commit:
https://github.com/qt/qtbase/commit/8936918a651ac297c91bfd285995993b306347ab

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
19 files changed:
src/core/io/qfilesystemengine.cpp
src/core/io/qresource.cpp
src/core/io/qurl.cpp
src/core/kernel/qcoreapplication.cpp
src/core/tools/qlocale.cpp
src/core/tools/qstring.cpp
src/gui/dialogs/qcolordialog.cpp
src/gui/kernel/qshortcut.cpp
src/gui/painting/qbezier.cpp
src/gui/painting/qdrawutil.cpp
src/gui/painting/qpaintengine_raster.cpp
src/gui/painting/qtextureglyphcache.cpp
src/gui/styles/qcommonstyle.cpp
src/gui/text/qfontsubset.cpp
src/gui/text/qtextengine.cpp
src/network/kernel/qauthenticator.cpp
src/test/qtestlog.cpp
src/tools/moc/moc.cpp
src/tools/uic/cpp/cppwriteicondata.cpp

index 4744f80..7704969 100644 (file)
 #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
index 82acb58..47eaeb7 100644 (file)
@@ -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;
index 59c1a15..925d1fd 100644 (file)
@@ -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) {
index c8e80ae..59b96c6 100644 (file)
@@ -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)
index 64536cb..4de891e 100644 (file)
@@ -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;
 }
index 5e1b865..fa2a62a 100644 (file)
@@ -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<ushort *>(malloc(size * sizeof(QChar)));
+        QChar *tmp = static_cast<QChar *>(::malloc(size * sizeof(QChar)));
         Q_CHECK_PTR(tmp);
-        memcpy(tmp, s, size * sizeof(QChar));
-        insert(i, reinterpret_cast<const QChar *>(tmp), size);
-        free(tmp);
+        ::memcpy(tmp, s, size * sizeof(QChar));
+        insert(i, tmp, size);
+        ::free(tmp);
         return *this;
     }
 
index 792500f..b4318d7 100644 (file)
@@ -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()) {
index e939893..c94da20 100644 (file)
@@ -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();
index 382770b..1bc30bb 100644 (file)
@@ -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;
index 4def623..31c534b 100644 (file)
@@ -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:
index 71837ec..082d5d4 100644 (file)
@@ -2640,7 +2640,6 @@ void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSp
     }
     if (n) {
         fg->blend(n, spans, fg);
-        n = 0;
     }
 }
 
index 9e9073f..992fc51 100644 (file)
@@ -132,7 +132,6 @@ bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const
     }
 
     QHash<GlyphAndSubPixelPosition, Coord> 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;
index 412ef74..4c2efca 100644 (file)
@@ -4539,7 +4539,7 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
         if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(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))) {
index 202401d..23c0e23 100644 (file)
@@ -973,7 +973,7 @@ static void convertPath(const QPainterPath &path, QList<TTF_POINT> *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;
                     }
index f396899..91a74a4 100644 (file)
@@ -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;
                             }
index 4937e93..6558dcc 100644 (file)
@@ -491,7 +491,6 @@ QHash<QByteArray, QByteArray> QAuthenticatorPrivate::parseDigestAuthenticationCh
             ++d;
         if (d >= end)
             break;
-        start = d;
         QByteArray value;
         while (d < end) {
             bool backslash = false;
index c00673d..7e95c96 100644 (file)
@@ -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;
index 08df63e..c0804f4 100644 (file)
@@ -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))
index fbbb90e..35722ba 100644 (file)
@@ -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)