From 6a22e8cb35cfccbacd65b56e193bf2ae83f205ea Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 24 Jun 2019 13:06:11 +0200 Subject: shiboken: Fix out of bounds string access Fix warning: (shiboken) Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt. introduced by qtbase/c2d2757bccc68e1b981df059786c2e76f2969530 (5.14). This happens when endPos is modified by the prior call to parseType(). Change-Id: I3b81e674c0aa118bd003aa25d8c61d89d772366f Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken2/ApiExtractor/typesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp') diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 344313e87..b4c94695d 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -3384,7 +3384,7 @@ AddedFunction::AddedFunction(QString signature, const QString &returnType) : if (!arg.name.isEmpty()) m_arguments.append({argumentName, arg}); // end of parameters... - if (signature[endPos] == QLatin1Char(')')) + if (endPos >= signatureLength || signature[endPos] == QLatin1Char(')')) break; } // is const? -- cgit v1.2.3 From ddfbbd346b522703a5b6f8d274a7f79983e5f319 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 25 Jun 2019 09:33:27 +0200 Subject: shiboken: Introduce nullptr Apply Fixits by Qt Creator with some amendments. Change-Id: Ie8300ddb834adb8b649324562f2c912a4e8cf4ce Reviewed-by: Christian Tismer --- sources/shiboken2/ApiExtractor/typesystem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp') diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index b4c94695d..d90e68175 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -698,7 +698,7 @@ bool Handler::endElement(const QStringRef &localName) if (m_currentDroppedEntryDepth == 1) { m_current = m_currentDroppedEntry->parent; delete m_currentDroppedEntry; - m_currentDroppedEntry = 0; + m_currentDroppedEntry = nullptr; m_currentDroppedEntryDepth = 0; } else { --m_currentDroppedEntryDepth; @@ -785,7 +785,7 @@ bool Handler::endElement(const QStringRef &localName) case StackElement::EnumTypeEntry: m_current->entry->setDocModification(m_contextStack.top()->docModifications); m_contextStack.top()->docModifications = DocModificationList(); - m_currentEnum = 0; + m_currentEnum = nullptr; break; case StackElement::Template: m_database->addTemplate(m_current->value.templateEntry); @@ -2807,7 +2807,7 @@ bool Handler::startElement(const QXmlStreamReader &reader) return false; } - StackElement topElement = !m_current ? StackElement(0) : *m_current; + StackElement topElement = !m_current ? StackElement(nullptr) : *m_current; element->entry = topElement.entry; switch (element->type) { @@ -3003,7 +3003,7 @@ QString PrimitiveTypeEntry::targetLangApiName() const PrimitiveTypeEntry *PrimitiveTypeEntry::basicReferencedTypeEntry() const { if (!m_referencedTypeEntry) - return 0; + return nullptr; PrimitiveTypeEntry *baseReferencedTypeEntry = m_referencedTypeEntry->basicReferencedTypeEntry(); return baseReferencedTypeEntry ? baseReferencedTypeEntry : m_referencedTypeEntry; @@ -3926,7 +3926,7 @@ struct CustomConversion::CustomConversionPrivate struct CustomConversion::TargetToNativeConversion::TargetToNativeConversionPrivate { TargetToNativeConversionPrivate() - : sourceType(0) + : sourceType(nullptr) { } const TypeEntry* sourceType; -- cgit v1.2.3 From e5595a4b3010b1bb4b6f80a0339271a7b26934de Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 25 Jun 2019 09:51:39 +0200 Subject: shiboken: Introduce auto Apply Fixits by Qt Creator with some amendments. Change-Id: Ib2be1012ef7e8a2ad0e6cd130371bf1e941c4264 Reviewed-by: Christian Tismer --- sources/shiboken2/ApiExtractor/typesystem.cpp | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp') diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index d90e68175..dc3036671 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -510,7 +510,7 @@ Handler::~Handler() = default; static QString readerFileName(const QXmlStreamReader &reader) { - const QFile *file = qobject_cast(reader.device()); + const auto *file = qobject_cast(reader.device()); return file != nullptr ? file->fileName() : QString(); } @@ -728,7 +728,7 @@ bool Handler::endElement(const QStringRef &localName) case StackElement::ValueTypeEntry: case StackElement::InterfaceTypeEntry: case StackElement::NamespaceTypeEntry: { - ComplexTypeEntry *centry = static_cast(m_current->entry); + auto *centry = static_cast(m_current->entry); centry->setAddedFunctions(m_contextStack.top()->addedFunctions); centry->setFunctionModifications(m_contextStack.top()->functionMods); centry->setFieldModifications(m_contextStack.top()->fieldMods); @@ -1148,8 +1148,7 @@ SmartPointerTypeEntry * return nullptr; } - SmartPointerTypeEntry *type = - new SmartPointerTypeEntry(name, getter, smartPointerType, refCountMethodName, since); + auto *type = new SmartPointerTypeEntry(name, getter, smartPointerType, refCountMethodName, since); applyCommonAttributes(type, attributes); return type; } @@ -1159,7 +1158,7 @@ PrimitiveTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - PrimitiveTypeEntry *type = new PrimitiveTypeEntry(name, since); + auto *type = new PrimitiveTypeEntry(name, since); applyCommonAttributes(type, attributes); for (int i = attributes->size() - 1; i >= 0; --i) { const QStringRef name = attributes->at(i).qualifiedName(); @@ -1203,7 +1202,7 @@ ContainerTypeEntry * m_error = QLatin1String("there is no container of type ") + typeName.toString(); return nullptr; } - ContainerTypeEntry *type = new ContainerTypeEntry(name, containerType, since); + auto *type = new ContainerTypeEntry(name, containerType, since); applyCommonAttributes(type, attributes); return type; } @@ -1220,7 +1219,7 @@ EnumTypeEntry * scope = fullName.left(sep); name = fullName.right(fullName.size() - sep - 2); } - EnumTypeEntry *entry = new EnumTypeEntry(scope, name, since); + auto *entry = new EnumTypeEntry(scope, name, since); applyCommonAttributes(entry, attributes); entry->setTargetLangPackage(m_defaultPackage); @@ -1258,7 +1257,7 @@ ObjectTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - ObjectTypeEntry *otype = new ObjectTypeEntry(name, since); + auto *otype = new ObjectTypeEntry(name, since); applyCommonAttributes(otype, attributes); QString targetLangName = name; bool generate = true; @@ -1331,7 +1330,7 @@ ValueTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - ValueTypeEntry *typeEntry = new ValueTypeEntry(name, since); + auto *typeEntry = new ValueTypeEntry(name, since); applyCommonAttributes(typeEntry, attributes); const int defaultCtIndex = indexOfAttribute(*attributes, QStringViewLiteral("default-constructor")); @@ -1356,7 +1355,7 @@ FunctionTypeEntry * TypeEntry *existingType = m_database->findType(name); if (!existingType) { - FunctionTypeEntry *result = new FunctionTypeEntry(name, signature, since); + auto *result = new FunctionTypeEntry(name, signature, since); applyCommonAttributes(result, attributes); return result; } @@ -1367,7 +1366,7 @@ FunctionTypeEntry * return nullptr; } - FunctionTypeEntry *result = reinterpret_cast(existingType); + auto *result = reinterpret_cast(existingType); result->addSignature(signature); return result; } @@ -1626,7 +1625,7 @@ TypeSystemTypeEntry *Handler::parseRootElement(const QXmlStreamReader &, } } - TypeSystemTypeEntry *moduleEntry = + auto *moduleEntry = const_cast(m_database->findTypeSystemType(m_defaultPackage)); const bool add = moduleEntry == nullptr; if (add) @@ -1768,7 +1767,7 @@ bool Handler::parseCustomConversion(const QXmlStreamReader &, } } - CustomConversion* customConversion = new CustomConversion(m_current->entry); + auto *customConversion = new CustomConversion(m_current->entry); customConversionsForReview.append(customConversion); return true; } @@ -2305,7 +2304,7 @@ CustomFunction * else if (name == QLatin1String("param-name")) paramName = attributes->takeAt(i).value().toString(); } - CustomFunction *func = new CustomFunction(functionName); + auto *func = new CustomFunction(functionName); func->paramName = paramName; return func; } @@ -2604,7 +2603,7 @@ bool Handler::startElement(const QXmlStreamReader &reader) return true; } - StackElement* element = new StackElement(m_current); + auto *element = new StackElement(m_current); element->type = elementType; if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateAll) -- cgit v1.2.3 From 4ccfd8de6462ce2ed938587eb0518038640c310f Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 29 May 2019 14:59:09 +0200 Subject: shiboken: Fix various clang warnings - Avoid copying complex types by using const ref - Use isEmpty() to check for container emptyness - Use range-based for - Use Q_DISABLE_COPY in 'public:' area - Fix spelling error - Use '= default' for trivial constructors/destructors - Remove non-null checks before deletion - Fix misleading indentation - Fix else after return - Simplify boolean expressions - Fix unused parameters, streamline code Change-Id: I8c6cadd8653e220ba8e5bdb4dd55524d13a81768 Reviewed-by: Christian Tismer --- sources/shiboken2/ApiExtractor/typesystem.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp') diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index dc3036671..65e3443da 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -1650,8 +1650,8 @@ bool Handler::loadTypesystem(const QXmlStreamReader &, const QStringRef name = attributes->at(i).qualifiedName(); if (name == nameAttribute()) typeSystemName = attributes->takeAt(i).value().toString(); - else if (name == generateAttribute()) - generateChild = convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true); + else if (name == generateAttribute()) + generateChild = convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true); } if (typeSystemName.isEmpty()) { m_error = QLatin1String("No typesystem name specified"); @@ -1804,8 +1804,8 @@ bool Handler::parseAddConversion(const QXmlStreamReader &, const QStringRef name = attributes->at(i).qualifiedName(); if (name == QLatin1String("type")) sourceTypeName = attributes->takeAt(i).value().toString(); - else if (name == QLatin1String("check")) - typeCheck = attributes->takeAt(i).value().toString(); + else if (name == QLatin1String("check")) + typeCheck = attributes->takeAt(i).value().toString(); } if (sourceTypeName.isEmpty()) { m_error = QLatin1String("Target to Native conversions must specify the input type with the 'type' attribute."); @@ -3042,9 +3042,10 @@ FunctionModificationList ComplexTypeEntry::functionModifications(const QString & FieldModification ComplexTypeEntry::fieldModification(const QString &name) const { - for (int i = 0; i < m_fieldMods.size(); ++i) - if (m_fieldMods.at(i).name == name) - return m_fieldMods.at(i); + for (const auto &fieldMod : m_fieldMods) { + if (fieldMod.name == name) + return fieldMod; + } FieldModification mod; mod.name = name; mod.modifiers = FieldModification::Readable | FieldModification::Writable; -- cgit v1.2.3