forked from qt-creator/qt-creator
C++: Fix dangling IDocument* in CppCompletionAssistProcessor
Steps to reproduce the crash: 1. Open some long file, e.g. botan.cpp 2. Trigger completion and close editor immediately The IDocument pointer was only used to reference the file name. Instead of passing an IDocument* to the IAssistInterface, pass the file name. Change-Id: Iafce9b818806a77968a10541114bc9b7c8665f11 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com> Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -77,7 +77,7 @@ static QStringList getCompletions(TestData &data, bool *replaceAccessOperator =
|
||||
QStringList completions;
|
||||
|
||||
CppCompletionAssistInterface *ai = new CppCompletionAssistInterface(data.editor->document(), data.pos,
|
||||
data.editor->editorDocument(), ExplicitlyInvoked,
|
||||
data.editor->editorDocument()->fileName(), ExplicitlyInvoked,
|
||||
data.snapshot, QStringList(), QStringList());
|
||||
CppCompletionAssistProcessor processor;
|
||||
IAssistProposal *proposal = processor.perform(ai);
|
||||
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
return new CppTools::Internal::CppCompletionAssistInterface(
|
||||
document,
|
||||
position,
|
||||
editor()->document(),
|
||||
editor()->document()->fileName(),
|
||||
reason,
|
||||
modelManager->snapshot(),
|
||||
includePaths,
|
||||
@@ -975,7 +975,7 @@ int CppCompletionAssistProcessor::startCompletionHelper()
|
||||
|
||||
int line = 0, column = 0;
|
||||
Convenience::convertPosition(m_interface->textDocument(), startOfExpression, &line, &column);
|
||||
const QString fileName = m_interface->document()->fileName();
|
||||
const QString fileName = m_interface->fileName();
|
||||
return startCompletionInternal(fileName, line, column, expression, endOfExpression);
|
||||
}
|
||||
|
||||
@@ -1000,7 +1000,7 @@ bool CppCompletionAssistProcessor::tryObjCCompletion()
|
||||
const int startPos = tokens[start].begin() + tokens.startPosition();
|
||||
const QString expr = m_interface->textAt(startPos, m_interface->position() - startPos);
|
||||
|
||||
Document::Ptr thisDocument = m_interface->snapshot().document(m_interface->document()->fileName());
|
||||
Document::Ptr thisDocument = m_interface->snapshot().document(m_interface->fileName());
|
||||
if (! thisDocument)
|
||||
return false;
|
||||
|
||||
@@ -1143,7 +1143,7 @@ bool CppCompletionAssistProcessor::completeInclude(const QTextCursor &cursor)
|
||||
|
||||
// Make completion for all relevant includes
|
||||
QStringList includePaths = m_interface->includePaths();
|
||||
const QString ¤tFilePath = QFileInfo(m_interface->document()->fileName()).path();
|
||||
const QString ¤tFilePath = QFileInfo(m_interface->fileName()).path();
|
||||
if (!includePaths.contains(currentFilePath))
|
||||
includePaths.append(currentFilePath);
|
||||
|
||||
@@ -1204,7 +1204,7 @@ bool CppCompletionAssistProcessor::objcKeywordsWanted() const
|
||||
if (!m_objcEnabled)
|
||||
return false;
|
||||
|
||||
const QString fileName = m_interface->document()->fileName();
|
||||
const QString fileName = m_interface->fileName();
|
||||
|
||||
const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase();
|
||||
return mdb->findByFile(fileName).type() == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE);
|
||||
|
||||
@@ -167,12 +167,12 @@ class CppCompletionAssistInterface : public TextEditor::DefaultAssistInterface
|
||||
public:
|
||||
CppCompletionAssistInterface(QTextDocument *textDocument,
|
||||
int position,
|
||||
Core::IDocument *document,
|
||||
const QString &fileName,
|
||||
TextEditor::AssistReason reason,
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
const QStringList &includePaths,
|
||||
const QStringList &frameworkPaths)
|
||||
: TextEditor::DefaultAssistInterface(textDocument, position, document, reason)
|
||||
: TextEditor::DefaultAssistInterface(textDocument, position, fileName, reason)
|
||||
, m_snapshot(snapshot)
|
||||
, m_includePaths(includePaths)
|
||||
, m_frameworkPaths(frameworkPaths)
|
||||
|
||||
Reference in New Issue
Block a user