X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=lexer.c;h=b6d5ceb6d3bd94aed4e4cc0bb0d2926d932b9b6a;hb=refs%2Fheads%2Fgraphitemaster%2Fthreading;hp=6c8ccd9db127c82c11996ccf82a08037e196c840;hpb=87d9371a5c08f5b05ba70b11c63df80960b40831;p=xonotic%2Fgmqcc.git diff --git a/lexer.c b/lexer.c index 6c8ccd9..b6d5ceb 100644 --- a/lexer.c +++ b/lexer.c @@ -766,6 +766,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) int ch = 0; int nextch; bool hex; + bool oct; char u8buf[8]; /* way more than enough */ int u8len, uc; @@ -851,17 +852,18 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) chr = 0; nextch = lex_getch(lex); hex = (nextch == 'x'); - if (!hex) + oct = (nextch == '0'); + if (!hex && !oct) lex_ungetch(lex, nextch); for (nextch = lex_getch(lex); nextch != '}'; nextch = lex_getch(lex)) { - if (!hex) { + if (!hex && !oct) { if (nextch >= '0' && nextch <= '9') chr = chr * 10 + nextch - '0'; else { lexerror(lex, "bad character code"); return (lex->tok.ttype = TOKEN_ERROR); } - } else { + } else if (!oct) { if (nextch >= '0' && nextch <= '9') chr = chr * 0x10 + nextch - '0'; else if (nextch >= 'a' && nextch <= 'f') @@ -872,6 +874,13 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) lexerror(lex, "bad character code"); return (lex->tok.ttype = TOKEN_ERROR); } + } else { + if (nextch >= '0' && nextch <= '9') + chr = chr * 8 + chr - '0'; + else { + lexerror(lex, "bad character code"); + return (lex->tok.ttype = TOKEN_ERROR); + } } if (chr > 0x10FFFF || (!OPTS_FLAG(UTF8) && chr > 255)) {