Refactor HighlightingResultReporter

In some unlikely circumstances it may happen that
HighlightingResultReporter might be destroyed before
returning from the HighlightingResultReporter::start()
function. This may lead to undefined behavior.

Refactor the HighlightingResultReporter so that instead
of using QRunnable subclass we define simple function
returning the QFuture object directly.

Change-Id: Ib833771a7e46e87c83d10b59ca056a0147fabe88
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2021-10-20 13:27:01 +02:00
parent ec633061d4
commit 0101808407
4 changed files with 64 additions and 130 deletions

View File

@@ -37,6 +37,8 @@
#include <diagnosticcontainer.h>
#include <sourcelocationcontainer.h>
#include <clangsupport/tokeninfocontainer.h>
#include <cppeditor/builtincursorinfo.h>
#include <cppeditor/clangdiagnosticconfigsmodel.h>
#include <cppeditor/compileroptionsbuilder.h>
@@ -271,10 +273,7 @@ void ClangEditorDocumentProcessor::updateHighlighting(
emit ifdefedOutBlocksUpdated(documentRevision, skippedPreprocessorBlocks);
m_semanticHighlighter.setHighlightingRunner(
[tokenInfos]() {
auto *reporter = new HighlightingResultReporter(tokenInfos);
return reporter->start();
});
[tokenInfos]() { return highlightResults(tokenInfos); });
m_semanticHighlighter.run();
}
}