From f0f623bcb8858a916366bfcf8d8b22795fd6197b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 7 Oct 2010 14:47:25 +0200 Subject: Fix crash related to 'add definition from declaration' quickfix. Reviewed-by: hjk Reviewed-by: Erik Verbruggen --- src/plugins/cppeditor/cppinsertdecldef.cpp | 6 ++++-- src/plugins/texteditor/refactoringchanges.cpp | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp index 9414a42148..e7ae40d85b 100644 --- a/src/plugins/cppeditor/cppinsertdecldef.cpp +++ b/src/plugins/cppeditor/cppinsertdecldef.cpp @@ -287,8 +287,10 @@ QList DefFromDecl::match(const CppQuickFixState &stat CppRefactoringChanges refactoring(state.snapshot()); InsertionPointLocator locator(&refactoring); QList results; - foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) - results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc))); + foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) { + if (loc.isValid()) + results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc))); + } return results; } } diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 3cc5118441..303424dfac 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -202,7 +202,7 @@ RefactoringFile::RefactoringFile(const RefactoringFile &other) RefactoringFile::~RefactoringFile() { - if (m_refactoringChanges && m_openEditor) + if (m_refactoringChanges && m_openEditor && !m_fileName.isEmpty()) m_editor = m_refactoringChanges->openEditor(m_fileName, -1); // apply changes, if any @@ -227,14 +227,15 @@ RefactoringFile::~RefactoringFile() } // if this document doesn't have an editor, write the result to a file - if (!m_editor) { + if (!m_editor && !m_fileName.isEmpty()) { const QByteArray &newContents = doc->toPlainText().toUtf8(); QFile file(m_fileName); file.open(QFile::WriteOnly); file.write(newContents); } - m_refactoringChanges->fileChanged(m_fileName); + if (!m_fileName.isEmpty()) + m_refactoringChanges->fileChanged(m_fileName); } delete m_document; @@ -254,9 +255,9 @@ QTextDocument *RefactoringFile::mutableDocument() const { if (m_editor) return m_editor->document(); - else if (!m_document && !m_fileName.isEmpty()) { + else if (!m_document) { QString fileContents; - { + if (!m_fileName.isEmpty()) { QFile file(m_fileName); if (file.open(QIODevice::ReadOnly)) fileContents = file.readAll(); -- cgit v1.2.1