From ef8a5518be2fc76b81e8dc0ef589e3d591ed33a7 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Wed, 6 Feb 2019 09:30:08 +0800 Subject: [PATCH] Fix crash when opening file with ANSI encoding on some systems (issue #97, introduced by aca3551b94e89da2a39000864b27901dabc2a66a). --- scintilla/win32/PlatWin.cxx | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 7442794ae2..dff708dca4 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -2106,28 +2106,28 @@ void SurfaceD2D::MeasureWidths(const Font &font_, std::string_view text, XYPOSIT while (i < text.length()) { positions[i++] = lastPos; } - } else if (codePageText == 0) { - - // One char per position - PLATFORM_ASSERT(text.length() == static_cast(tbuf.tlen)); - for (int kk = 0; kk < tbuf.tlen; kk++) { - positions[kk] = poses.buffer[kk]; - } - } else { const DBCSCharClassify *dbcs = DBCSCharClassify::Get(codePageText); - // May be one or two bytes per position - int ui = 0; - for (size_t i = 0; i < text.length() && ui < tbuf.tlen;) { - positions[i] = poses.buffer[ui]; - if (dbcs->IsLeadByte(text[i])) { - positions[i + 1] = poses.buffer[ui]; - i += 2; - } else { - i++; - } + if (dbcs) { + // May be one or two bytes per position + int ui = 0; + for (size_t i = 0; i < text.length() && ui < tbuf.tlen;) { + positions[i] = poses.buffer[ui]; + if (dbcs->IsLeadByte(text[i])) { + positions[i + 1] = poses.buffer[ui]; + i += 2; + } else { + i++; + } - ui++; + ui++; + } + } else { + // One char per position + PLATFORM_ASSERT(text.length() == static_cast(tbuf.tlen)); + for (int kk = 0; kk < tbuf.tlen; kk++) { + positions[kk] = poses.buffer[kk]; + } } } }