diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-20 17:17:11 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-20 17:17:11 +0200 |
commit | 1006be240d4fbb68e4f690c9963011aeec596624 (patch) | |
tree | 64ef39f20ad9e4a6c3612ea0921f6f9589365862 /src/plugins/cpptools/cppcodecompletion.cpp | |
parent | 7c68acbd3f50f159f065d0d6abfc37b18dddcb1c (diff) | |
download | qt-creator-1006be240d4fbb68e4f690c9963011aeec596624.tar.gz |
Fixed possible crash when completing top-level declarations.
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 6dbbe4ad86..b62c421658 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -1019,8 +1019,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi // find a scope that encloses the current location, starting from the lastVisibileSymbol // and moving outwards - Scope *sc = context.symbol()->scope(); - while (sc->enclosingScope()) { + Scope *sc = 0; + if (context.symbol()) + sc = context.symbol()->scope(); + else if (context.thisDocument()) + sc = context.thisDocument()->globalSymbols(); + + while (sc && sc->enclosingScope()) { unsigned startLine, startColumn; context.thisDocument()->translationUnit()->getPosition(sc->owner()->startOffset(), &startLine, &startColumn); unsigned endLine, endColumn; @@ -1034,7 +1039,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi sc = sc->enclosingScope(); } - if (sc->isClassScope() || sc->isNamespaceScope()) + if (sc && (sc->isClassScope() || sc->isNamespaceScope())) { // It may still be a function call. If the whole line parses as a function // declaration, we should be certain that it isn't. |