widl: Check for overflow when parsing integer constants.
This commit is contained in:
parent
f24678b285
commit
cb3ea6843c
|
@ -47,6 +47,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)*
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
|
@ -82,6 +83,19 @@ struct {
|
|||
} import_stack[MAX_IMPORT_DEPTH];
|
||||
int import_stack_ptr = 0;
|
||||
|
||||
/* converts an integer in string form to an unsigned long and prints an error
|
||||
* on overflow */
|
||||
static unsigned long xstrtoul(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(nptr, endptr, base);
|
||||
if (l == ULONG_MAX && errno == ERANGE)
|
||||
error_loc("integer constant %s is too large\n", nptr);
|
||||
return l;
|
||||
}
|
||||
|
||||
UUID *parse_uuid(const char *u)
|
||||
{
|
||||
UUID* uuid = xmalloc(sizeof(UUID));
|
||||
|
@ -154,11 +168,11 @@ UUID *parse_uuid(const char *u)
|
|||
return aUUID;
|
||||
}
|
||||
<INITIAL,ATTR>{hex} {
|
||||
parser_lval.num = strtoul(yytext, NULL, 0);
|
||||
parser_lval.num = xstrtoul(yytext, NULL, 0);
|
||||
return aHEXNUM;
|
||||
}
|
||||
<INITIAL,ATTR>{int} {
|
||||
parser_lval.num = strtoul(yytext, NULL, 0);
|
||||
parser_lval.num = xstrtoul(yytext, NULL, 0);
|
||||
return aNUM;
|
||||
}
|
||||
<INITIAL>{double} {
|
||||
|
|
Loading…
Reference in New Issue