Add more utf8 checks.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15842 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-02-01 06:49:44 +00:00
parent 11cb628f81
commit c6559096e0

View file

@ -1038,7 +1038,7 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
} }
if (c < 0xe0) if (c < 0xe0)
{ {
if (c < 0xc2) if (c < 0xc1)
{ {
/* /*
* Either we are inside a multibyte sequence or * Either we are inside a multibyte sequence or
@ -1072,13 +1072,30 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
} }
c2 = src[spos++]; c2 = src[spos++];
if (((c1 ^ 0x80) >= 0x40) || ((c2 ^ 0x80) >= 0x40) if (((c1 ^ 0x80) >= 0x40) || ((c2 ^ 0x80) >= 0x40)
|| (c1 == 0x80)) || (c == 0xe0 && c1 == 0x80))
{ {
result = NO; // Invalid sequence. result = NO; // Invalid sequence.
break; break;
} }
u = ((c & 0x0f) << 12) | ((c1 & 0x3f) << 6) u = ((c & 0x0f) << 12) | ((c1 & 0x3f) << 6)
| (c2 & 0x3f); | (c2 & 0x3f);
if (u >= 0xd800 && u <= 0xdfff)
{
/*
* Sequence not legal ... in utf-16 surrogates.
*/
result = NO;
break;
}
if (u >= 0xfffe)
{
/*
* Sequence not legal ... in utf-16 surrogates.
*/
result = NO;
break;
}
} }
else else
{ {