From 88e390fbc0cd1a67489c65279ee456fd752608c5 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 28 Oct 2015 01:57:47 +0100 Subject: [PATCH] Fix 3 bytes file open issue (Fixes #725) Open a file of 3 bytes length with '\0' in the middle, only 1 character shown in editor. Such file is detected as UTF16 w/o BOM, that makes the wrong length interpretation. Adding the "len mod 2 == 0" condition to enhance the detection is the only solution I can find so far. --- PowerEditor/src/Utf8_16.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerEditor/src/Utf8_16.cpp b/PowerEditor/src/Utf8_16.cpp index 1532c7586..6bb7d2660 100644 --- a/PowerEditor/src/Utf8_16.cpp +++ b/PowerEditor/src/Utf8_16.cpp @@ -205,7 +205,7 @@ void Utf8_16_Read::determineEncoding() m_nSkip = 3; } // try to detect UTF-16 little-endian without BOM - else if (m_nLen > 1 && m_pBuf[0] != NULL && m_pBuf[1] == NULL && IsTextUnicode(m_pBuf, m_nLen, &uniTest)) + else if (m_nLen > 1 && m_nLen % 2 == 0 && m_pBuf[0] != NULL && m_pBuf[1] == NULL && IsTextUnicode(m_pBuf, m_nLen, &uniTest)) { m_eEncoding = uni16LE_NoBOM; m_nSkip = 0;