X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=lexer.cpp;h=1007948958caf4103a108feb3b97633af2277af7;hp=79ad182a6456a439e1bfe8ee0cfa9989844aa35a;hb=2d4a054440e9fdf12edc202188ae4ea2e4ce90b5;hpb=76278e8b97578f210b34784a55925b043098def9 diff --git a/lexer.cpp b/lexer.cpp index 79ad182..1007948 100644 --- a/lexer.cpp +++ b/lexer.cpp @@ -65,7 +65,7 @@ static void lex_token_new(lex_file *lex) if (lex->tok.value) vec_shrinkto(lex->tok.value, 0); - lex->tok.constval.t = 0; + lex->tok.constval.t = TYPE_VOID; lex->tok.ctx.line = lex->sline; lex->tok.ctx.file = lex->name; lex->tok.ctx.column = lex->column; @@ -831,6 +831,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch) { bool ishex = false; + bool isoct = false; int ch = lastch; @@ -843,7 +844,16 @@ static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch) lex_tokench(lex, ch); ch = lex_getch(lex); - if (ch != '.' && !util_isdigit(ch)) + + if (lastch == '0' && util_isdigit(ch)) { + if (ch < '0' || ch > '7') { + lexerror(lex, "invalid octal constant"); + return (lex->tok.ttype = TOKEN_ERROR); + } + isoct = true; + } + + if (!isoct && ch != '.' && !util_isdigit(ch)) { if (lastch != '0' || ch != 'x') { @@ -898,10 +908,15 @@ static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch) lex_ungetch(lex, ch); lex_endtoken(lex); - if (lex->tok.ttype == TOKEN_FLOATCONST) + if (lex->tok.ttype == TOKEN_FLOATCONST) { lex->tok.constval.f = strtod(lex->tok.value, nullptr); - else - lex->tok.constval.i = strtol(lex->tok.value, nullptr, 0); + } else { + /* determine base for strtol */ + int base = 10; + if (ishex) base = 16; + if (isoct) base = 8; + lex->tok.constval.i = strtol(lex->tok.value, nullptr, base); + } return lex->tok.ttype; }