From 755659e663fe2295fd3cb61e5ef0fc0ba6cf2e37 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 20 Jul 2020 21:17:52 +0200 Subject: 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 --- src/plugins/cpptools/cpprefactoringchanges.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/plugins/cpptools/cpprefactoringchanges.cpp') 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 createIndenter(QTextDocument *textDocument) + static std::unique_ptr createIndenter(const QString &fileName, + QTextDocument *textDocument) { TextEditor::ICodeStylePreferencesFactory *factory = TextEditor::TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID); - return std::unique_ptr(factory->createIndenter(textDocument)); + std::unique_ptr 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); } } -- cgit v1.2.1