mirror of https://github.com/OpenTTD/OpenTTD
(svn r27233) -Fix [FS#6272]: crash when no AIs were installed due to improper handling of non-ASCII characters by the string pointer lexer
parent
262c3c93c8
commit
5ed8ac8a81
|
@ -1261,10 +1261,28 @@ struct BufState{
|
||||||
|
|
||||||
WChar buf_lexfeed(SQUserPointer file)
|
WChar buf_lexfeed(SQUserPointer file)
|
||||||
{
|
{
|
||||||
BufState *buf=(BufState*)file;
|
/* Convert an UTF-8 character into a WChar */
|
||||||
if(buf->size<(buf->ptr+1))
|
BufState *buf = (BufState *)file;
|
||||||
return 0;
|
const char *p = &buf->buf[buf->ptr];
|
||||||
return buf->buf[buf->ptr++];
|
|
||||||
|
if (buf->size < buf->ptr + 1) return 0;
|
||||||
|
|
||||||
|
/* Read the first character, and get the length based on UTF-8 specs. If invalid, bail out. */
|
||||||
|
uint len = Utf8EncodedCharLen(*p);
|
||||||
|
if (len == 0) {
|
||||||
|
buf->ptr++;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the remaining bits. */
|
||||||
|
if (buf->size < buf->ptr + len) return 0;
|
||||||
|
buf->ptr += len;
|
||||||
|
|
||||||
|
/* Convert the character, and when definitely invalid, bail out as well. */
|
||||||
|
WChar c;
|
||||||
|
if (Utf8Decode(&c, p) != len) return -1;
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror) {
|
SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror) {
|
||||||
|
|
Loading…
Reference in New Issue