C++: fix possible nullptr deref.

Pointed out by the clang static analyzer.

Change-Id: I69ab89e651cbcb13606d5d93a05f629172cbd9e0
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Erik Verbruggen
2014-09-10 11:53:39 +02:00
parent 0ed377466c
commit ebcd4ce8db

View File

@@ -1884,7 +1884,7 @@ bool Bind::visit(SimpleDeclarationAST *ast)
const ExpressionAST *initializer = it->value->initializer;
if (!initializer && declaratorId)
translationUnit()->error(location(declaratorId->name, ast->firstToken()), "auto-initialized variable must have an initializer");
else {
else if (initializer) {
unsigned startOfExpression = initializer->firstToken();
unsigned endOfExpression = initializer->lastToken();
decl->setInitializer(asStringLiteral(startOfExpression, endOfExpression));