summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpprefactoringchanges.cpp
diff options
context:
space:
mode:
authorLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-07-20 21:17:52 +0200
committerLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-07-28 14:17:54 +0000
commit755659e663fe2295fd3cb61e5ef0fc0ba6cf2e37 (patch)
treee2ba290bc8109073ceb279c035aaf683f5ecf8ca /src/plugins/cpptools/cpprefactoringchanges.cpp
parent200d81d38ce70873f44315fc2530b6b0c8cd7693 (diff)
downloadqt-creator-755659e663fe2295fd3cb61e5ef0fc0ba6cf2e37.tar.gz
CppTools: Prevent SegFault in the ClangFormatIndenter
If you create a ClangFormatIndenter but do not set the fileName, the indenter will SegFault while indenting. Change-Id: I93a56d7916bc1a02da9ee21a116bd48b4405edb1 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cpprefactoringchanges.cpp')
-rw-r--r--src/plugins/cpptools/cpprefactoringchanges.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp
index 5ebd490ea6..509506d5a1 100644
--- a/src/plugins/cpptools/cpprefactoringchanges.cpp
+++ b/src/plugins/cpptools/cpprefactoringchanges.cpp
@@ -47,11 +47,14 @@ namespace CppTools {
class CppRefactoringChangesData : public TextEditor::RefactoringChangesData
{
- static std::unique_ptr<TextEditor::Indenter> createIndenter(QTextDocument *textDocument)
+ static std::unique_ptr<TextEditor::Indenter> createIndenter(const QString &fileName,
+ QTextDocument *textDocument)
{
TextEditor::ICodeStylePreferencesFactory *factory
= TextEditor::TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID);
- return std::unique_ptr<TextEditor::Indenter>(factory->createIndenter(textDocument));
+ std::unique_ptr<TextEditor::Indenter> indenter(factory->createIndenter(textDocument));
+ indenter->setFileName(Utils::FilePath::fromString(fileName));
+ return indenter;
}
public:
@@ -69,7 +72,7 @@ public:
textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
} else {
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
- auto indenter = createIndenter(selection.document());
+ auto indenter = createIndenter(fileName, selection.document());
indenter->indent(selection, QChar::Null, tabSettings);
}
}
@@ -82,7 +85,7 @@ public:
textDocument->indenter()->reindent(selection, textDocument->tabSettings());
} else {
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
- auto indenter = createIndenter(selection.document());
+ auto indenter = createIndenter(fileName, selection.document());
indenter->reindent(selection, tabSettings);
}
}