From: Jeremy Kerr Date: Tue, 17 Sep 2013 01:34:34 +0000 (+0800) Subject: discover/grub2: Improve error handling X-Git-Tag: v1.0.0~453 X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=d808f5d2ec8e232d736a5f811d647df91e2a5b43 discover/grub2: Improve error handling Only run the script if the parse succeeded, and and improve the error reporting by enabling verbose errors and line numbers. Signed-off-by: Jeremy Kerr --- diff --git a/discover/grub2/lexer.l b/discover/grub2/lexer.l index 3e1f9fa..6c0a456 100644 --- a/discover/grub2/lexer.l +++ b/discover/grub2/lexer.l @@ -12,6 +12,7 @@ %option stack noyy_top_state %option reentrant %option bison-bridge +%option yylineno %option noyyalloc noyyfree noyyrealloc %option extra-type="struct grub2_parser *" %option header-file="lexer.h" diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y index e13cd72..550c374 100644 --- a/discover/grub2/parser.y +++ b/discover/grub2/parser.y @@ -2,6 +2,7 @@ %pure-parser %lex-param { yyscan_t scanner } %parse-param { struct grub2_parser *parser } +%error-verbose %{ #include @@ -244,13 +245,15 @@ struct grub2_parser *grub2_parser_create(struct discover_context *ctx) void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len) { YY_BUFFER_STATE bufstate; + int rc; bufstate = yy_scan_bytes(buf, len - 1, parser->scanner); - yyparse(parser); + rc = yyparse(parser); yy_delete_buffer(bufstate, parser->scanner); - script_execute(parser->script); + if (!rc) + script_execute(parser->script); }