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:
parent
6750be3432
commit
9734d81f32
|
@ -629,24 +629,18 @@ void Utf16_Iter::operator++()
|
||||||
m_highSurrogate = m_nCur16;
|
m_highSurrogate = m_nCur16;
|
||||||
}
|
}
|
||||||
else if (m_nCur16 < 0x80) {
|
else if (m_nCur16 < 0x80) {
|
||||||
pushout(static_cast<ubyte>(m_nCur16 & 0xFF));
|
pushout(static_cast<ubyte>(m_nCur16));
|
||||||
m_eState = eStart;
|
m_eState = eStart;
|
||||||
} else if (m_nCur16 < 0x800) {
|
} else if (m_nCur16 < 0x800) {
|
||||||
pushout(static_cast<ubyte>(0xC0 | m_nCur16 >> 6));
|
pushout(static_cast<ubyte>(0xC0 | m_nCur16 >> 6));
|
||||||
m_eState = e2Bytes2;
|
pushout(0x80 | m_nCur16 & 0x3f);
|
||||||
} else {
|
|
||||||
pushout(static_cast<ubyte>(0xE0 | m_nCur16 >> 12));
|
|
||||||
m_eState = e3Bytes2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case e2Bytes2:
|
|
||||||
case e3Bytes3:
|
|
||||||
pushout(static_cast<ubyte>(0x80 | m_nCur16 & 0x3F));
|
|
||||||
m_eState = eStart;
|
m_eState = eStart;
|
||||||
break;
|
} else {
|
||||||
case e3Bytes2:
|
pushout(0xE0 | (m_nCur16 >> 12));
|
||||||
pushout(static_cast<ubyte>(0x80 | ((m_nCur16 >> 6) & 0x3F)));
|
pushout(0x80 | (m_nCur16 >> 6) & 0x3f);
|
||||||
m_eState = e3Bytes3;
|
pushout(0x80 | m_nCur16 & 0x3f);
|
||||||
|
m_eState = eStart;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case eSurrogate:
|
case eSurrogate:
|
||||||
read();
|
read();
|
||||||
|
@ -657,8 +651,8 @@ void Utf16_Iter::operator++()
|
||||||
pushout(0x80 | (code >> 12) & 0x3f);
|
pushout(0x80 | (code >> 12) & 0x3f);
|
||||||
pushout(0x80 | (code >> 6) & 0x3f);
|
pushout(0x80 | (code >> 6) & 0x3f);
|
||||||
pushout(0x80 | code & 0x3f);
|
pushout(0x80 | code & 0x3f);
|
||||||
m_eState = eStart;
|
|
||||||
}
|
}
|
||||||
|
m_eState = eStart;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,6 @@ class Utf16_Iter : public Utf8_16 {
|
||||||
public:
|
public:
|
||||||
enum eState {
|
enum eState {
|
||||||
eStart,
|
eStart,
|
||||||
e2Bytes2,
|
|
||||||
e3Bytes2,
|
|
||||||
e3Bytes3,
|
|
||||||
eSurrogate
|
eSurrogate
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,7 +49,7 @@ public:
|
||||||
bool get(utf8 *c);
|
bool get(utf8 *c);
|
||||||
void operator++();
|
void operator++();
|
||||||
eState getState() { return m_eState; };
|
eState getState() { return m_eState; };
|
||||||
operator bool() { return m_pRead < m_pEnd; };
|
operator bool() { return (m_pRead < m_pEnd) || (m_out1st != m_outLst); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void read();
|
void read();
|
||||||
|
@ -81,7 +78,7 @@ public:
|
||||||
bool canGet() const { return m_out1st != m_outLst; }
|
bool canGet() const { return m_out1st != m_outLst; }
|
||||||
void toStart();
|
void toStart();
|
||||||
void operator++();
|
void operator++();
|
||||||
operator bool() { return m_pRead < m_pEnd; }
|
operator bool() { return (m_pRead < m_pEnd) || (m_out1st != m_outLst); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum eState {eStart, eFollow};
|
enum eState {eStart, eFollow};
|
||||||
|
|
Loading…
Reference in New Issue