diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-22 14:29:57 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-23 16:30:11 +0100 |
commit | 31de5e520d69d47d9710ad8b97aee62ce053916f (patch) | |
tree | c0e72b2ffe5058fc0a569c84a366010a9ce9d370 | |
parent | b5083b2a037c57dde225925ddf94e1c76ba97f54 (diff) |
Further clean up some warnings produced by Qt Creator's clang/clazy code checkers
- Remove unused variables
- Fix potential memory leak in type system parser
- Initialize return values
- Use const ref to avoid copies
- Integer conversions
Change-Id: Ib84236d58849143e9ae6af0079985503b773bca3
Reviewed-by: Christian Tismer <tismer@stackless.com>
4 files changed, 16 insertions, 15 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 3a196e487..34eb89a6b 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -2560,6 +2560,8 @@ AbstractMetaClass* AbstractMetaBuilderPrivate::findTemplateClass(const QString & TypeInfo *info, ComplexTypeEntry **baseContainerType) const { + if (baseContainerType) + *baseContainerType = nullptr; TypeDatabase* types = TypeDatabase::instance(); QStringList scope = context->typeEntry()->qualifiedCppName().split(colonColon()); diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index 84986b281..c11f0d46b 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -2089,8 +2089,8 @@ bool TypeSystemParser::parseRename(const QXmlStreamReader &, return true; } -bool TypeSystemParser::parseModifyField(const QXmlStreamReader &reader, - QXmlStreamAttributes *attributes) +bool TypeSystemParser::parseModifyField(const QXmlStreamReader &, + QXmlStreamAttributes *attributes) { FieldModification fm; for (int i = attributes->size() - 1; i >= 0; --i) { @@ -2713,7 +2713,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) return true; } - auto *element = new StackElement(m_current); + std::unique_ptr<StackElement> element(new StackElement(m_current)); element->type = elementType; if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateCode) @@ -2761,8 +2761,8 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) if (m_database->hasDroppedTypeEntries()) { const QString identifier = element->type == StackElement::FunctionTypeEntry ? attributes.value(signatureAttribute()).toString() : name; - if (shouldDropTypeEntry(m_database, element, identifier)) { - m_currentDroppedEntry = element; + if (shouldDropTypeEntry(m_database, element.get(), identifier)) { + m_currentDroppedEntry = element.release(); m_currentDroppedEntryDepth = 1; if (ReportHandler::isDebug(ReportHandler::SparseDebug)) { qCInfo(lcShiboken, "Type system entry '%s' was intentionally dropped from generation.", @@ -3038,7 +3038,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) m_contextStack.top()->functionMods.last().argument_mods().last().setArray(true); break; case StackElement::InjectCode: - if (!parseInjectCode(reader, topElement, element, &attributes)) + if (!parseInjectCode(reader, topElement, element.get(), &attributes)) return false; break; case StackElement::Include: @@ -3070,7 +3070,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) return false; break; case StackElement::Replace: - if (!parseReplace(reader, topElement, element, &attributes)) + if (!parseReplace(reader, topElement, element.get(), &attributes)) return false; break; default: @@ -3083,6 +3083,6 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) qCWarning(lcShiboken, "%s", qPrintable(msgReaderWarning(reader, message))); } - m_current = element; + m_current = element.release(); return true; } diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index d15434c50..3b51f7c0d 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -515,7 +515,7 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon // Manifested as crash when calling QPlainTextEdit::find() (clash with // static QWidget::find(WId)). if (!staticEncountered) { - for (int i = overloads.size() - 1; i >= 0; --i) { + for (qsizetype i = overloads.size() - 1; i >= 0; --i) { if (overloads.at(i)->isStatic()) overloads.removeAt(i); } @@ -1253,7 +1253,7 @@ void CppGenerator::writeMetaObjectMethod(TextStream &s, CodeSnipList snips; if (list.size() == 1) { - const auto func = list.constFirst(); + const auto &func = list.constFirst(); snips = func->injectedCodeSnips(); if (func->isUserAdded()) { CodeSnipList snips = func->injectedCodeSnips(); @@ -2392,7 +2392,7 @@ static void checkTypeViability(const AbstractMetaFunctionCPtr &func) } void CppGenerator::writeTypeCheck(TextStream &s, const OverloadData *overloadData, - QString argumentName) const + const QString &argumentName) const { QSet<const TypeEntry *> numericTypes; const OverloadDataList &overloads = overloadData->previousOverloadData()->nextOverloadData(); @@ -4162,7 +4162,6 @@ void CppGenerator::writeClassDefinition(TextStream &s, QString tp_dealloc; QString tp_hash; QString tp_call; - QString cppClassName = metaClass->qualifiedCppName(); const QString className = chopType(cpythonTypeName(metaClass)); QString baseClassName; AbstractMetaFunctionCList ctors; @@ -4570,7 +4569,7 @@ void CppGenerator::writeGetterFunction(TextStream &s, writeCppSelfDefinition(s, context); - AbstractMetaType fieldType = metaField.type(); + const AbstractMetaType &fieldType = metaField.type(); // Force use of pointer to return internal variable memory bool newWrapperSameObject = !fieldType.isConstant() && fieldType.isWrapperType() && !fieldType.isPointer(); @@ -6275,7 +6274,7 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF ArgumentOwner::Action action = argOwner.action; int parentIndex = argOwner.index; int childIndex = argIndex; - if (ctorHeuristicEnabled && argIndex > 0 && numArgs) { + if (ctorHeuristicEnabled && argIndex > 0 && argIndex <= numArgs) { const AbstractMetaArgument &arg = func->arguments().at(argIndex-1); if (arg.name() == QLatin1String("parent") && arg.type().isObjectType()) { action = ArgumentOwner::Add; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index d3482d385..743dee124 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -118,7 +118,7 @@ private: bool isNumber = false, const QString &customType = QString(), bool rejectNull = false) const; void writeTypeCheck(TextStream& s, const OverloadData *overloadData, - QString argumentName) const; + const QString &argumentName) const; static void writeTypeDiscoveryFunction(TextStream &s, const AbstractMetaClass *metaClass); |