From 407889bc0fd381b1ff48c62f8b0d579b81f068b5 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Thu, 3 Jan 2019 07:50:19 +1100 Subject: Backport: Bug [#2073]. Stop GetCharacterAndWidth returning negative character value. This occurred for single-byte encodings and was never hit as GetCharacterAndWidth is only called for multi-byte encodings. Backport of changeset 7188:c836128fa848. --- src/Document.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Document.cxx b/src/Document.cxx index b6b1ce294..ad0ec80e7 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -930,8 +930,8 @@ Sci::Position Document::GetRelativePositionUTF16(Sci::Position positionStart, Sc int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const { int character; int bytesInCharacter = 1; + const unsigned char leadByte = cb.UCharAt(position); if (dbcsCodePage) { - const unsigned char leadByte = cb.UCharAt(position); if (SC_CP_UTF8 == dbcsCodePage) { if (UTF8IsAscii(leadByte)) { // Single byte character or invalid @@ -959,7 +959,7 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio } } } else { - character = cb.CharAt(position); + character = leadByte; } if (pWidth) { *pWidth = bytesInCharacter; -- cgit v1.2.3