diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-14 02:02:11 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-14 02:02:11 +0200 |
commit | 9929ac9123983ab82bf6b2eb609b19896e1af210 (patch) | |
tree | 5e6ab7af8d9b54fab1e62f9960b3433bd0dcfe62 /src/lex.c | |
parent | bf721f718ed2ca3e5d409a2f6b48312ee95d2e4e (diff) | |
download | fastd-9929ac9123983ab82bf6b2eb609b19896e1af210.tar fastd-9929ac9123983ab82bf6b2eb609b19896e1af210.zip |
lex: various fixes
Diffstat (limited to 'src/lex.c')
-rw-r--r-- | src/lex.c | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -169,21 +169,17 @@ static void consume(fastd_lex_t *lex, bool needspace) { lex->needspace = needspace; } -static int syntax_error(YYSTYPE *yylval, fastd_lex_t *lex) { - yylval->error = "syntax error"; - return -1; -} - static int io_error(YYSTYPE *yylval, fastd_lex_t *lex) { yylval->error = "I/O error"; return -1; } -static inline int end(YYSTYPE *yylval, fastd_lex_t *lex) { +static int syntax_error(YYSTYPE *yylval, fastd_lex_t *lex) { if (ferror(lex->file)) return io_error(yylval, lex); - return 0; + yylval->error = "syntax error"; + return -1; } static int consume_comment(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { @@ -268,7 +264,10 @@ static int parse_ipv6_address(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex if (lex->needspace) return syntax_error(yylval, lex); - while (next(yylloc, lex, false)) { + while (true) { + if (!next(yylloc, lex, false)) + return syntax_error(yylval, lex); + char cur = current(lex); if (!((cur >= '0' && cur <= '9') || cur == ':')) @@ -282,10 +281,8 @@ static int parse_ipv6_address(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex ok = inet_pton(AF_INET6, lex->buffer+lex->start+1, &yylval->addr6); } - if (!ok) { - yylval->error = "invalid address"; - return -1; - } + if (!ok) + return syntax_error(yylval, lex); next(yylloc, lex, true); consume(lex, true); @@ -309,10 +306,10 @@ static int parse_ipv4_address(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex free(token); - if (!ok) { - yylval->error = "invalid address"; - return -1; - } + if (!ok) + return syntax_error(yylval, lex); + + consume(lex, true); return TOK_ADDR4; } @@ -337,10 +334,10 @@ static int parse_number(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { bool ok = !*endptr; free(token); - if (!ok) { - yylval->error = "invalid integer constant"; - return -1; - } + if (!ok) + return syntax_error(yylval, lex); + + consume(lex, true); return TOK_UINT; } @@ -453,5 +450,8 @@ int fastd_lex(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { } } - return end(yylval, lex); + if (ferror(lex->file)) + return io_error(yylval, lex); + + return 0; } |