From: whitequark Date: Mon, 18 May 2020 03:18:42 +0000 (+0000) Subject: ilang_lexer: fix check for out of range literal. X-Git-Tag: working-ls180~525^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13b2963dedebf86129574192b0d4719956e93d82;p=yosys.git ilang_lexer: fix check for out of range literal. Commit ca70a104 did not use a correct check. --- diff --git a/frontends/ilang/ilang_lexer.l b/frontends/ilang/ilang_lexer.l index 62f53d18e..3362ed641 100644 --- a/frontends/ilang/ilang_lexer.l +++ b/frontends/ilang/ilang_lexer.l @@ -91,8 +91,10 @@ USING_YOSYS_NAMESPACE [0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; } -?[0-9]+ { char *end = nullptr; + errno = 0; long value = strtol(yytext, &end, 10); - if (end != yytext + strlen(yytext)) + log_assert(end == yytext + strlen(yytext)); + if (errno == ERANGE) return TOK_INVALID; // literal out of range of long if (value < INT_MIN || value > INT_MAX) return TOK_INVALID; // literal out of range of int (relevant mostly for LP64 platforms)