[colorer/Colorer-library] master: Fix parser crashes on transient null lines and temporary string lifetime (6aa463d)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Feb 25, 2026, 12:01:02 PM (2 days ago) Feb 25
to farco...@googlegroups.com
Repository : https://github.com/colorer/Colorer-library
On branch : master
Link : https://github.com/colorer/Colorer-library/commit/6aa463df491852be3af25ef721f1f675cc77fcd0

>---------------------------------------------------------------

commit 6aa463df491852be3af25ef721f1f675cc77fcd0
Author: Alexey Shelaev <75270873+e...@users.noreply.github.com>
Date: Sun Feb 8 23:22:31 2026 +0100

Fix parser crashes on transient null lines and temporary string lifetime


>---------------------------------------------------------------

6aa463df491852be3af25ef721f1f675cc77fcd0
src/colorer/parsers/TextParserImpl.cpp | 9 +++++++--
src/colorer/strings/legacy/UnicodeString.cpp | 4 +++-
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/colorer/parsers/TextParserImpl.cpp b/src/colorer/parsers/TextParserImpl.cpp
index 7f9335a..8d51b17 100644
--- a/src/colorer/parsers/TextParserImpl.cpp
+++ b/src/colorer/parsers/TextParserImpl.cpp
@@ -521,8 +521,13 @@ bool TextParser::Impl::colorize(CRegExp* root_end_re, bool lowContentPriority)
clearLine = current_parse_line;
str = lineSource->getLine(current_parse_line);
if (str == nullptr) {
- throw Exception("null String passed into the parser: " +
- UStr::to_unistr(current_parse_line));
+ // LineSource can return null if the line is not available (e.g. editor shutdown).
+ // Stop parsing gracefully instead of throwing across threads.
+ str = nullptr;
+ clearLine = -1;
+ endLine = current_parse_line;
+ stackLevel--;
+ return true;
}
regionHandler->clearLine(current_parse_line, str);
}
diff --git a/src/colorer/strings/legacy/UnicodeString.cpp b/src/colorer/strings/legacy/UnicodeString.cpp
index 227d4a3..bb3873c 100644
--- a/src/colorer/strings/legacy/UnicodeString.cpp
+++ b/src/colorer/strings/legacy/UnicodeString.cpp
@@ -3,6 +3,7 @@
#include <colorer/strings/legacy/Encodings.h>
#include <colorer/strings/legacy/UnicodeString.h>
#include <cstdlib>
+#include <string>
#include "colorer/Exception.h"

UnicodeString operator+(const UnicodeString& s1, const UnicodeString& s2)
@@ -90,7 +91,8 @@ UnicodeString::UnicodeString(const UnicodeString& cstring, int32_t s, int32_t l)

UnicodeString::UnicodeString(int no)
{
- CString dtext = CString(std::to_string(no).c_str());
+ const std::string number_text = std::to_string(no);
+ CString dtext = CString(number_text.c_str());
construct(&dtext, 0, npos);
}



Reply all
Reply to author
Forward
0 new messages