ilang_lexer: fix check for out of range literal.
authorwhitequark <whitequark@whitequark.org>
Mon, 18 May 2020 03:18:42 +0000 (03:18 +0000)
committerwhitequark <whitequark@whitequark.org>
Fri, 29 May 2020 06:58:44 +0000 (06:58 +0000)
Commit ca70a104 did not use a correct check.

frontends/ilang/ilang_lexer.l

index 62f53d18e69152be49c922d2052e24e53b309aca..3362ed641a5957175fd35a827f50495d8e364f92 100644 (file)
@@ -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)