From 13ab2a73b8e25d2f790d355b2f72753d791d5d91 Mon Sep 17 00:00:00 2001 From: Michael Urman Date: Tue, 19 Mar 2002 04:02:10 +0000 Subject: [PATCH] fix crash on nonexistent (or otherwise unopenable) include files. svn path=/trunk/yasm/; revision=536 --- modules/preprocs/yapp/yapp-token.l | 31 +++++++++++++++++------------- src/preprocs/yapp/yapp-token.l | 31 +++++++++++++++++------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/modules/preprocs/yapp/yapp-token.l b/modules/preprocs/yapp/yapp-token.l index 2d6854ae..6d42ee3b 100644 --- a/modules/preprocs/yapp/yapp-token.l +++ b/modules/preprocs/yapp/yapp-token.l @@ -159,7 +159,6 @@ DIR %[ \t]* } /* includes - based on flex manual handling of include files */ - /* FIXME: stop includes inside non-output zones from happening */ {DIR}include[^\n]* ; {DIR}include BEGIN(incl); /* note the " handling here is a hack that doesn't accept useful @@ -167,22 +166,28 @@ DIR %[ \t]* [ \t"]* /* eat whitespace */ [^ \t\n"]* { /* have the filename */ include *inc; + YY_BUFFER_STATE *incfile; inc = xmalloc(sizeof(include)); inc->include_state = YY_CURRENT_BUFFER; - inc->filename = current_file; - inc->line_number = line_number; - current_file = xstrdup(yytext); - SLIST_INSERT_HEAD(&includes_head, inc, next); /* FIXME: handle includes that aren't relative */ - yyin = fopen (yytext, "r"); - if(!yyin) - Error(_("File `%s' included from %s:%d cannot be opened"), - yytext, current_file, line_number); - - yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - BEGIN(INITIAL); - line_number = 1; + incfile = fopen (yytext, "r"); + if(!incfile) { + Error(_("include file `%s': %s"), + yytext, strerror(errno)); + free(inc); + } + else { + yyin = incfile; + inc->filename = current_file; + inc->line_number = line_number; + SLIST_INSERT_HEAD(&includes_head, inc, next); + + line_number = 1; + current_file = xstrdup(yytext); + BEGIN(INITIAL); + yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); + } return INCLUDE; } diff --git a/src/preprocs/yapp/yapp-token.l b/src/preprocs/yapp/yapp-token.l index 2d6854ae..6d42ee3b 100644 --- a/src/preprocs/yapp/yapp-token.l +++ b/src/preprocs/yapp/yapp-token.l @@ -159,7 +159,6 @@ DIR %[ \t]* } /* includes - based on flex manual handling of include files */ - /* FIXME: stop includes inside non-output zones from happening */ {DIR}include[^\n]* ; {DIR}include BEGIN(incl); /* note the " handling here is a hack that doesn't accept useful @@ -167,22 +166,28 @@ DIR %[ \t]* [ \t"]* /* eat whitespace */ [^ \t\n"]* { /* have the filename */ include *inc; + YY_BUFFER_STATE *incfile; inc = xmalloc(sizeof(include)); inc->include_state = YY_CURRENT_BUFFER; - inc->filename = current_file; - inc->line_number = line_number; - current_file = xstrdup(yytext); - SLIST_INSERT_HEAD(&includes_head, inc, next); /* FIXME: handle includes that aren't relative */ - yyin = fopen (yytext, "r"); - if(!yyin) - Error(_("File `%s' included from %s:%d cannot be opened"), - yytext, current_file, line_number); - - yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - BEGIN(INITIAL); - line_number = 1; + incfile = fopen (yytext, "r"); + if(!incfile) { + Error(_("include file `%s': %s"), + yytext, strerror(errno)); + free(inc); + } + else { + yyin = incfile; + inc->filename = current_file; + inc->line_number = line_number; + SLIST_INSERT_HEAD(&includes_head, inc, next); + + line_number = 1; + current_file = xstrdup(yytext); + BEGIN(INITIAL); + yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); + } return INCLUDE; } -- 2.40.0