Fix a special character in UTF16 file crash issue (regression)

Fix UTF iterators end too early.
This regression (https://github.com/notepad-plus-plus/notepad-plus-plus/pull/9599#issuecomment-825654605) is introduced via 38bf76e843

Close #9797
This commit is contained in:
Udo Hoffmann 2021-04-24 11:02:50 +02:00 committed by Don HO
parent 6750be3432
commit 9734d81f32
2 changed files with 10 additions and 19 deletions

View File

@ -629,24 +629,18 @@ void Utf16_Iter::operator++()
m_highSurrogate = m_nCur16;
}
else if (m_nCur16 < 0x80) {
pushout(static_cast<ubyte>(m_nCur16 & 0xFF));
pushout(static_cast<ubyte>(m_nCur16));
m_eState = eStart;
} else if (m_nCur16 < 0x800) {
pushout(static_cast<ubyte>(0xC0 | m_nCur16 >> 6));
m_eState = e2Bytes2;
pushout(0x80 | m_nCur16 & 0x3f);
m_eState = eStart;
} else {
pushout(static_cast<ubyte>(0xE0 | m_nCur16 >> 12));
m_eState = e3Bytes2;
pushout(0xE0 | (m_nCur16 >> 12));
pushout(0x80 | (m_nCur16 >> 6) & 0x3f);
pushout(0x80 | m_nCur16 & 0x3f);
m_eState = eStart;
}
break;
case e2Bytes2:
case e3Bytes3:
pushout(static_cast<ubyte>(0x80 | m_nCur16 & 0x3F));
m_eState = eStart;
break;
case e3Bytes2:
pushout(static_cast<ubyte>(0x80 | ((m_nCur16 >> 6) & 0x3F)));
m_eState = e3Bytes3;
break;
case eSurrogate:
read();
@ -657,8 +651,8 @@ void Utf16_Iter::operator++()
pushout(0x80 | (code >> 12) & 0x3f);
pushout(0x80 | (code >> 6) & 0x3f);
pushout(0x80 | code & 0x3f);
m_eState = eStart;
}
m_eState = eStart;
break;
}
}

View File

@ -40,9 +40,6 @@ class Utf16_Iter : public Utf8_16 {
public:
enum eState {
eStart,
e2Bytes2,
e3Bytes2,
e3Bytes3,
eSurrogate
};
@ -52,7 +49,7 @@ public:
bool get(utf8 *c);
void operator++();
eState getState() { return m_eState; };
operator bool() { return m_pRead < m_pEnd; };
operator bool() { return (m_pRead < m_pEnd) || (m_out1st != m_outLst); };
protected:
void read();
@ -81,7 +78,7 @@ public:
bool canGet() const { return m_out1st != m_outLst; }
void toStart();
void operator++();
operator bool() { return m_pRead < m_pEnd; }
operator bool() { return (m_pRead < m_pEnd) || (m_out1st != m_outLst); }
protected:
enum eState {eStart, eFollow};