Skip to content

Commit b7e7a39

Browse files
committed
fix: fix use after free crash
1 parent c8652b0 commit b7e7a39

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

plugins/builtin/include/content/text_highlighting/pattern_language.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace hex::plugin::builtin {
164164
/**
165165
* @brief Entry point to syntax highlighting
166166
*/
167-
void highlightSourceCode();
167+
void highlightSourceCode(const std::string& text);
168168
void processSource();
169169
void clearVariables();
170170

plugins/builtin/source/content/text_highlighting/pattern_language.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ namespace hex::plugin::builtin {
22462246

22472247

22482248
// Only update if needed. Must wait for the parser to finish first.
2249-
void TextHighlighter::highlightSourceCode() {
2249+
void TextHighlighter::highlightSourceCode(const std::string& text) {
22502250
m_wasInterrupted = false;
22512251
ON_SCOPE_EXIT {
22522252
if (!m_tokenColors.empty())
@@ -2298,10 +2298,7 @@ namespace hex::plugin::builtin {
22982298
m_globalTokenRange.insert(Interval(0, m_tokens.size()-1));
22992299

23002300
ui::TextEditor *editor = m_viewPatternEditor->getTextEditor();
2301-
if (editor != nullptr)
2302-
m_text = editor->getText();
2303-
else
2304-
log::warn("Text editor not found, provider is null");
2301+
m_text = text;
23052302

23062303
if (m_text.empty() || m_text == "\n")
23072304
return;

plugins/builtin/source/content/views/view_pattern_editor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,9 @@ namespace hex::plugin::builtin {
14351435
if (m_textHighlighter.getRunningColorizers() == 0) {
14361436
m_textHighlighter.m_needsToUpdateColors = false;
14371437
m_changesWereParsed = false;
1438-
TaskManager::createBackgroundTask("HighlightSourceCode", [this](auto &) { m_textHighlighter.highlightSourceCode(); });
1438+
1439+
auto text = m_textEditor.get(provider).getText();
1440+
TaskManager::createBackgroundTask("HighlightSourceCode", [this, text](auto &) { m_textHighlighter.highlightSourceCode(text); });
14391441
} else {
14401442
m_textHighlighter.interrupt();
14411443
}

0 commit comments

Comments
 (0)