- ch = ch * 10 + nextch - '0';
- if (nextch < '0' || nextch > '9' || ch > 255) {
- lexerror(lex, "bad character code");
+ if (!hex) {
+ if (nextch >= '0' && nextch <= '9')
+ chr = chr * 10 + nextch - '0';
+ else {
+ lexerror(lex, "bad character code");
+ return (lex->tok.ttype = TOKEN_ERROR);
+ }
+ } else {
+ if (nextch >= '0' && nextch <= '9')
+ chr = chr * 0x10 + nextch - '0';
+ else if (nextch >= 'a' && nextch <= 'f')
+ chr = chr * 0x10 + nextch - 'a' + 10;
+ else if (nextch >= 'A' && nextch <= 'F')
+ chr = chr * 0x10 + nextch - 'A' + 10;
+ else {
+ lexerror(lex, "bad character code");
+ return (lex->tok.ttype = TOKEN_ERROR);
+ }
+ }
+ if (chr > 0x10FFFF || (!OPTS_FLAG(UTF8) && chr > 255))
+ {
+ lexerror(lex, "character code out of range");