summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-03-18 14:58:46 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-03-19 14:12:11 +0100
commit947207c8020f6de25077481538e2855dc643c55e (patch)
tree0f5a11d913545b3e0b032bc44a5da28299516438
parent7f61d11311187b45e1bff859cd097eab59342cc7 (diff)
downloadqt-creator-947207c8020f6de25077481538e2855dc643c55e.tar.gz
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>
-rw-r--r--src/plugins/cppeditor/cppquickfix.cpp2
-rw-r--r--src/plugins/cppeditor/cppquickfixassistant.cpp3
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp2
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp10
-rw-r--r--src/plugins/cpptools/cppcompletionassist.h4
-rw-r--r--src/plugins/glsleditor/glslcompletionassist.cpp4
-rw-r--r--src/plugins/glsleditor/glslcompletionassist.h2
-rw-r--r--src/plugins/glsleditor/glsleditor.cpp2
-rw-r--r--src/plugins/qmljseditor/qmljscompletionassist.cpp6
-rw-r--r--src/plugins/qmljseditor/qmljscompletionassist.h2
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp2
-rw-r--r--src/plugins/qmljseditor/qmljsquickfixassist.cpp3
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp2
-rw-r--r--src/plugins/texteditor/codeassist/defaultassistinterface.cpp4
-rw-r--r--src/plugins/texteditor/codeassist/defaultassistinterface.h6
-rw-r--r--src/plugins/texteditor/codeassist/iassistinterface.h2
16 files changed, 29 insertions, 27 deletions
diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp
index efe46a9515..4557a96aaa 100644
--- a/src/plugins/cppeditor/cppquickfix.cpp
+++ b/src/plugins/cppeditor/cppquickfix.cpp
@@ -74,7 +74,7 @@ const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
QString CppQuickFixOperation::fileName() const
{
- return m_interface->document()->fileName();
+ return m_interface->fileName();
}
void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result)
diff --git a/src/plugins/cppeditor/cppquickfixassistant.cpp b/src/plugins/cppeditor/cppquickfixassistant.cpp
index 262b47950e..1644938e66 100644
--- a/src/plugins/cppeditor/cppquickfixassistant.cpp
+++ b/src/plugins/cppeditor/cppquickfixassistant.cpp
@@ -99,7 +99,8 @@ const IAssistProvider *CppQuickFixAssistProcessor::provider() const
// --------------------------
CppQuickFixAssistInterface::CppQuickFixAssistInterface(CPPEditorWidget *editor,
TextEditor::AssistReason reason)
- : DefaultAssistInterface(editor->document(), editor->position(), editor->editorDocument(), reason)
+ : DefaultAssistInterface(editor->document(), editor->position(),
+ editor->editorDocument()->fileName(), reason)
, m_editor(editor)
, m_semanticInfo(editor->semanticInfo())
, m_snapshot(CPlusPlus::CppModelManagerInterface::instance()->snapshot())
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 6e35e263da..823a478fe4 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -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);
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp
index 4bebd197f6..f4e2d91c38 100644
--- a/src/plugins/cpptools/cppcompletionassist.cpp
+++ b/src/plugins/cpptools/cppcompletionassist.cpp
@@ -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 &currentFilePath = QFileInfo(m_interface->document()->fileName()).path();
+ const QString &currentFilePath = 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);
diff --git a/src/plugins/cpptools/cppcompletionassist.h b/src/plugins/cpptools/cppcompletionassist.h
index e574fb413a..23d7b387bb 100644
--- a/src/plugins/cpptools/cppcompletionassist.h
+++ b/src/plugins/cpptools/cppcompletionassist.h
@@ -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)
diff --git a/src/plugins/glsleditor/glslcompletionassist.cpp b/src/plugins/glsleditor/glslcompletionassist.cpp
index 736ef2fd00..f5ecd2c983 100644
--- a/src/plugins/glsleditor/glslcompletionassist.cpp
+++ b/src/plugins/glsleditor/glslcompletionassist.cpp
@@ -463,11 +463,11 @@ void GLSLCompletionAssistProcessor::addCompletion(const QString &text,
// -----------------------------
GLSLCompletionAssistInterface::GLSLCompletionAssistInterface(QTextDocument *textDocument,
int position,
- Core::IDocument *document,
+ const QString &fileName,
TextEditor::AssistReason reason,
const QString &mimeType,
const Document::Ptr &glslDoc)
- : DefaultAssistInterface(textDocument, position, document, reason)
+ : DefaultAssistInterface(textDocument, position, fileName, reason)
, m_mimeType(mimeType)
, m_glslDoc(glslDoc)
{
diff --git a/src/plugins/glsleditor/glslcompletionassist.h b/src/plugins/glsleditor/glslcompletionassist.h
index 3aee1112ba..81d5c0a547 100644
--- a/src/plugins/glsleditor/glslcompletionassist.h
+++ b/src/plugins/glsleditor/glslcompletionassist.h
@@ -96,7 +96,7 @@ class GLSLCompletionAssistInterface : public TextEditor::DefaultAssistInterface
{
public:
GLSLCompletionAssistInterface(QTextDocument *textDocument,
- int position, Core::IDocument *document,
+ int position, const QString &fileName,
TextEditor::AssistReason reason,
const QString &mimeType,
const Document::Ptr &glslDoc);
diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp
index 9e17f4121a..3d22d82633 100644
--- a/src/plugins/glsleditor/glsleditor.cpp
+++ b/src/plugins/glsleditor/glsleditor.cpp
@@ -416,7 +416,7 @@ TextEditor::IAssistInterface *GLSLTextEditorWidget::createAssistInterface(
if (kind == TextEditor::Completion)
return new GLSLCompletionAssistInterface(document(),
position(),
- editor()->document(),
+ editor()->document()->fileName(),
reason,
mimeType(),
glslDocument());
diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp
index 621d090b0f..f50179facf 100644
--- a/src/plugins/qmljseditor/qmljscompletionassist.cpp
+++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp
@@ -530,7 +530,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
if (assistInterface->reason() == IdleEditor && !acceptsIdleEditor())
return 0;
- const QString &fileName = m_interface->document()->fileName();
+ const QString &fileName = m_interface->fileName();
m_startPosition = assistInterface->position();
while (isIdentifierChar(m_interface->textDocument()->characterAt(m_startPosition - 1), false, false))
@@ -964,10 +964,10 @@ bool QmlJSCompletionAssistProcessor::completeUrl(const QString &relativeBasePath
// ------------------------------
QmlJSCompletionAssistInterface::QmlJSCompletionAssistInterface(QTextDocument *textDocument,
int position,
- Core::IDocument *document,
+ const QString &fileName,
TextEditor::AssistReason reason,
const SemanticInfo &info)
- : DefaultAssistInterface(textDocument, position, document, reason)
+ : DefaultAssistInterface(textDocument, position, fileName, reason)
, m_semanticInfo(info)
, m_darkBlueIcon(iconForColor(Qt::darkBlue))
, m_darkYellowIcon(iconForColor(Qt::darkYellow))
diff --git a/src/plugins/qmljseditor/qmljscompletionassist.h b/src/plugins/qmljseditor/qmljscompletionassist.h
index dced072d9e..04fa64cd45 100644
--- a/src/plugins/qmljseditor/qmljscompletionassist.h
+++ b/src/plugins/qmljseditor/qmljscompletionassist.h
@@ -120,7 +120,7 @@ class QmlJSCompletionAssistInterface : public TextEditor::DefaultAssistInterface
public:
QmlJSCompletionAssistInterface(QTextDocument *textDocument,
int position,
- Core::IDocument *document,
+ const QString &fileName,
TextEditor::AssistReason reason,
const QmlJSTools::SemanticInfo &info);
const QmlJSTools::SemanticInfo &semanticInfo() const;
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index c35bb34c90..cbd3f6f394 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -1424,7 +1424,7 @@ TextEditor::IAssistInterface *QmlJSTextEditorWidget::createAssistInterface(
if (assistKind == TextEditor::Completion) {
return new QmlJSCompletionAssistInterface(document(),
position(),
- editor()->document(),
+ editor()->document()->fileName(),
reason,
m_semanticInfo);
} else if (assistKind == TextEditor::QuickFix) {
diff --git a/src/plugins/qmljseditor/qmljsquickfixassist.cpp b/src/plugins/qmljseditor/qmljsquickfixassist.cpp
index c88869b299..8c705c743c 100644
--- a/src/plugins/qmljseditor/qmljsquickfixassist.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfixassist.cpp
@@ -45,7 +45,8 @@ using namespace TextEditor;
// -----------------------
QmlJSQuickFixAssistInterface::QmlJSQuickFixAssistInterface(QmlJSTextEditorWidget *editor,
TextEditor::AssistReason reason)
- : DefaultAssistInterface(editor->document(), editor->position(), editor->editorDocument(), reason)
+ : DefaultAssistInterface(editor->document(), editor->position(),
+ editor->editorDocument()->fileName(), reason)
, m_editor(editor)
, m_semanticInfo(editor->semanticInfo())
, m_currentFile(QmlJSRefactoringChanges::file(m_editor, m_semanticInfo.document))
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 14e5682a55..52c03e4374 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -6681,7 +6681,7 @@ IAssistInterface *BaseTextEditorWidget::createAssistInterface(AssistKind kind,
AssistReason reason) const
{
Q_UNUSED(kind);
- return new DefaultAssistInterface(document(), position(), d->m_document.data(), reason);
+ return new DefaultAssistInterface(document(), position(), d->m_document->fileName(), reason);
}
QString TextEditor::BaseTextEditorWidget::foldReplacementText(const QTextBlock &) const
diff --git a/src/plugins/texteditor/codeassist/defaultassistinterface.cpp b/src/plugins/texteditor/codeassist/defaultassistinterface.cpp
index 6cb3c80b87..d8a376d709 100644
--- a/src/plugins/texteditor/codeassist/defaultassistinterface.cpp
+++ b/src/plugins/texteditor/codeassist/defaultassistinterface.cpp
@@ -39,12 +39,12 @@ using namespace TextEditor;
DefaultAssistInterface::DefaultAssistInterface(QTextDocument *textDocument,
int position,
- Core::IDocument *document,
+ const QString &fileName,
AssistReason reason)
: m_textDocument(textDocument)
, m_isAsync(false)
, m_position(position)
- , m_document(document)
+ , m_fileName(fileName)
, m_reason(reason)
{}
diff --git a/src/plugins/texteditor/codeassist/defaultassistinterface.h b/src/plugins/texteditor/codeassist/defaultassistinterface.h
index 68ef4b7b51..e7c2e241d2 100644
--- a/src/plugins/texteditor/codeassist/defaultassistinterface.h
+++ b/src/plugins/texteditor/codeassist/defaultassistinterface.h
@@ -39,14 +39,14 @@ class TEXTEDITOR_EXPORT DefaultAssistInterface : public IAssistInterface
public:
DefaultAssistInterface(QTextDocument *textDocument,
int position,
- Core::IDocument *document,
+ const QString &fileName,
AssistReason reason);
virtual ~DefaultAssistInterface();
virtual int position() const { return m_position; }
virtual QChar characterAt(int position) const;
virtual QString textAt(int position, int length) const;
- virtual const Core::IDocument *document() const { return m_document; }
+ virtual QString fileName() const { return m_fileName; }
virtual QTextDocument *textDocument() const { return m_textDocument; }
virtual void prepareForAsyncUse();
virtual void recreateTextDocument();
@@ -56,7 +56,7 @@ private:
QTextDocument *m_textDocument;
bool m_isAsync;
int m_position;
- Core::IDocument *m_document;
+ QString m_fileName;
AssistReason m_reason;
QString m_text;
};
diff --git a/src/plugins/texteditor/codeassist/iassistinterface.h b/src/plugins/texteditor/codeassist/iassistinterface.h
index 17d91681ac..67c30be2cf 100644
--- a/src/plugins/texteditor/codeassist/iassistinterface.h
+++ b/src/plugins/texteditor/codeassist/iassistinterface.h
@@ -56,7 +56,7 @@ public:
virtual int position() const = 0;
virtual QChar characterAt(int position) const = 0;
virtual QString textAt(int position, int length) const = 0;
- virtual const Core::IDocument *document() const = 0;
+ virtual QString fileName() const = 0;
virtual QTextDocument *textDocument() const = 0;
virtual void prepareForAsyncUse() = 0;
virtual void recreateTextDocument() = 0;