OSDN Git Service

correct strcmp() and strncmp() return value checks
authorIvailo Monev <xakepa10@gmail.com>
Tue, 21 Sep 2021 11:31:02 +0000 (14:31 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 21 Sep 2021 11:31:02 +0000 (14:31 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/kernel/qmetatype.cpp
src/core/kernel/qobjectdefs.h
src/dbus/qdbusabstractadaptor.cpp
src/dbus/qdbusinterface.cpp
src/script/bridge/qscriptqobject.cpp
src/test/qtestlogger.cpp
src/test/qtestxmlstreamer.cpp
src/test/qxmltestlogger.cpp
src/tools/moc/generator.cpp

index ecefe2d..974879c 100644 (file)
@@ -419,7 +419,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
     for (int v = 0; v < ct->count(); ++v) {
         const QCustomTypeInfo &customInfo = ct->at(v);
         if ((length == customInfo.typeName.size())
-            && !strcmp(typeName, customInfo.typeName.constData())) {
+            && strcmp(typeName, customInfo.typeName.constData()) == 0) {
             if (customInfo.alias >= 0)
                 return customInfo.alias;
             return v + QMetaType::User;
index d8cb331..e4d3fc9 100644 (file)
@@ -32,7 +32,7 @@ class QByteArray;
 
 class QString;
 
-#define Q_MOC_OUTPUT_REVISION 65
+#define Q_MOC_OUTPUT_REVISION 66
 
 // The following macros are our "extensions" to C++
 // They are used, strictly speaking, only by the moc.
index b46923f..f924478 100644 (file)
@@ -356,7 +356,7 @@ const QMetaObject *QDBusAdaptorConnector::metaObject() const
 void *QDBusAdaptorConnector::qt_metacast(const char *_clname)
 {
     if (!_clname) return nullptr;
-    if (!strcmp(_clname, qt_meta_stringdata_QDBusAdaptorConnector))
+    if (strcmp(_clname, qt_meta_stringdata_QDBusAdaptorConnector) == 0)
         return static_cast<void*>(const_cast< QDBusAdaptorConnector*>(this));
     return QObject::qt_metacast(_clname);
 }
index ae11bbe..fdf5e17 100644 (file)
@@ -225,7 +225,7 @@ const QMetaObject *QDBusInterface::metaObject() const
 void *QDBusInterface::qt_metacast(const char *_clname)
 {
     if (!_clname) return 0;
-    if (!strcmp(_clname, "QDBusInterface"))
+    if (strcmp(_clname, "QDBusInterface") == 0)
         return static_cast<void*>(this);
     if (d_func()->interface.toLatin1() == _clname)
         return static_cast<void*>(this);
index e1e4e5b..06855a8 100644 (file)
@@ -2111,7 +2111,7 @@ const QMetaObject *QScript::QObjectConnectionManager::metaObject() const
 void *QScript::QObjectConnectionManager::qt_metacast(const char *_clname)
 {
     if (!_clname) return nullptr;
-    if (!strcmp(_clname, qt_meta_stringdata_QScript__QObjectConnectionManager))
+    if (strcmp(_clname, qt_meta_stringdata_QScript__QObjectConnectionManager) == 0)
         return static_cast<void*>(this);
     return QObject::qt_metacast(_clname);
 }
index 9944115..9323ece 100644 (file)
@@ -209,20 +209,17 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description,
     if (resultAttr) {
         const char* oldResult = resultAttr->value();
         bool overwrite = false;
-        if (!strcmp(oldResult, "pass")) {
+        if (strcmp(oldResult, "pass") == 0) {
             overwrite = true;
-        }
-        else if (!strcmp(oldResult, "xfail")) {
+        } else if (strcmp(oldResult, "xfail") == 0) {
             overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail);
-        }
-        else if (!strcmp(oldResult, "xpass")) {
+        } else if (strcmp(oldResult, "xpass") == 0) {
             overwrite = (type == QAbstractTestLogger::Fail);
         }
         if (overwrite) {
             resultAttr->setPair(QTest::AI_Result, typeBuf);
         }
-    }
-    else {
+    } else {
         currentLogElement->addAttribute(QTest::AI_Result, typeBuf);
     }
 
index 11b9180..ed25bde 100644 (file)
@@ -139,10 +139,10 @@ void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *f
     if (element->elementType() == QTest::LET_TestCase) {
         bool failed = false;
         for (QTestElement* child = element->childElements(); child; child = child->nextElement()) {
-            if (   child->elementType() == QTest::LET_Failure
+            if (child->elementType() == QTest::LET_Failure
                 && child->attribute(QTest::AI_Result)
-                && (    !strcmp(child->attributeValue(QTest::AI_Result), "fail")
-                    ||  !strcmp(child->attributeValue(QTest::AI_Result), "xpass"))
+                && (strcmp(child->attributeValue(QTest::AI_Result), "fail") == 0
+                    || strcmp(child->attributeValue(QTest::AI_Result), "xpass") == 0)
                 )
             {
                 failed = true;
index 9d80cf4..9da6a19 100644 (file)
@@ -363,7 +363,7 @@ int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n
             return (dest-begin);
         }
 
-        if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
+        if (strncmp(src, CDATA_END, sizeof(CDATA_END)-1) == 0) {
             if (dest + sizeof(CDATA_END_ESCAPED) < end) {
                 strcpy(dest, CDATA_END_ESCAPED);
                 src += sizeof(CDATA_END)-1;
index 7e5686c..e756d2f 100644 (file)
@@ -347,20 +347,20 @@ void Generator::generateCode()
 //
     fprintf(out, "\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->qualified.constData());
     fprintf(out, "    if (!_clname) return nullptr;\n");
-    fprintf(out, "    if (!strcmp(_clname, qt_meta_stringdata_%s))\n"
+    fprintf(out, "    if (strcmp(_clname, qt_meta_stringdata_%s) == 0)\n"
                   "        return static_cast<void*>(this);\n",
             qualifiedClassNameIdentifier.constData());
     for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one
         if (cdef->superclassList.at(i).second == FunctionDef::Private)
             continue;
         const char *cname = cdef->superclassList.at(i).first.constData();
-        fprintf(out, "    if (!strcmp(_clname, \"%s\"))\n        return static_cast<%s*>(const_cast<%s*>(this));\n",
+        fprintf(out, "    if (strcmp(_clname, \"%s\") == 0)\n        return static_cast<%s*>(const_cast<%s*>(this));\n",
                 cname, cname, cdef->classname.constData());
     }
     for (int i = 0; i < cdef->interfaceList.size(); ++i) {
         const QList<ClassDef::Interface> &iface = cdef->interfaceList.at(i);
         for (int j = 0; j < iface.size(); ++j) {
-            fprintf(out, "    if (!strcmp(_clname, %s))\n        return ", iface.at(j).interfaceId.constData());
+            fprintf(out, "    if (strcmp(_clname, %s) == 0)\n        return ", iface.at(j).interfaceId.constData());
             for (int k = j; k >= 0; --k)
                 fprintf(out, "static_cast<%s*>(", iface.at(k).className.constData());
             fprintf(out, "const_cast<%s*>(this)%s;\n",