AutoTest: Fix possible nullptr access

Task-number: QTCREATORBUG-16062
Change-Id: Ifa544390f27b3ff73d74e4766dc93762bf152da8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-04-14 11:46:45 +02:00
parent 3b2d9e0d4f
commit d0a6f70380

View File

@@ -385,15 +385,17 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
CPlusPlus::TypeOfExpression typeOfExpr; CPlusPlus::TypeOfExpression typeOfExpr;
typeOfExpr.init(doc, cppMM->snapshot()); typeOfExpr.init(doc, cppMM->snapshot());
auto lookupItems = typeOfExpr(testCaseName.toUtf8(), doc->globalNamespace()); QList<CPlusPlus::LookupItem> lookupItems = typeOfExpr(testCaseName.toUtf8(),
doc->globalNamespace());
if (lookupItems.size()) { if (lookupItems.size()) {
CPlusPlus::Class *toeClass = lookupItems.first().declaration()->asClass(); if (CPlusPlus::Symbol *symbol = lookupItems.first().declaration()) {
if (toeClass) { if (CPlusPlus::Class *toeClass = symbol->asClass()) {
const QString declFileName = QLatin1String(toeClass->fileId()->chars(), const QString declFileName = QLatin1String(toeClass->fileId()->chars(),
toeClass->fileId()->size()); toeClass->fileId()->size());
declaringDoc = cppMM->snapshot().document(declFileName); declaringDoc = cppMM->snapshot().document(declFileName);
*line = toeClass->line(); *line = toeClass->line();
*column = toeClass->column() - 1; *column = toeClass->column() - 1;
}
} }
} }
return declaringDoc; return declaringDoc;