mirror of https://github.com/YosysHQ/yosys.git
read_ilang: detect overflow of integer literals.
This commit is contained in:
parent
cf716e1fff
commit
ca70a1049f
|
@ -29,6 +29,7 @@
|
|||
#pragma clang diagnostic ignored "-Wdeprecated-register"
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include "frontends/ilang/ilang_frontend.h"
|
||||
#include "ilang_parser.tab.hh"
|
||||
|
||||
|
@ -88,7 +89,16 @@ USING_YOSYS_NAMESPACE
|
|||
"."[0-9]+ { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_ID; }
|
||||
|
||||
[0-9]+'[01xzm-]* { rtlil_frontend_ilang_yylval.string = strdup(yytext); return TOK_VALUE; }
|
||||
-?[0-9]+ { rtlil_frontend_ilang_yylval.integer = atoi(yytext); return TOK_INT; }
|
||||
-?[0-9]+ {
|
||||
char *end = NULL;
|
||||
long value = strtol(yytext, &end, 10);
|
||||
if (end != yytext + strlen(yytext))
|
||||
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)
|
||||
rtlil_frontend_ilang_yylval.integer = value;
|
||||
return TOK_INT;
|
||||
}
|
||||
|
||||
\" { BEGIN(STRING); }
|
||||
<STRING>\\. { yymore(); }
|
||||
|
|
Loading…
Reference in New Issue