(svn r27233) -Fix [FS#6272]: crash when no AIs were installed due to improper handling of non-ASCII characters by the string pointer lexer

This commit is contained in:
rubidium 2015-04-11 19:33:36 +00:00
parent 262c3c93c8
commit 5ed8ac8a81

View File

@ -1261,10 +1261,28 @@ struct BufState{
WChar buf_lexfeed(SQUserPointer file) WChar buf_lexfeed(SQUserPointer file)
{ {
/* Convert an UTF-8 character into a WChar */
BufState *buf = (BufState *)file; BufState *buf = (BufState *)file;
if(buf->size<(buf->ptr+1)) const char *p = &buf->buf[buf->ptr];
return 0;
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) {