From 1524572ce96fcef2871b2dcda3eaf3161b2b8469 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 2 Dec 2007 13:08:03 +0000 Subject: [PATCH] * parse.y (parser_tokadd_mbchar): fix for ASCII chars. [ruby-dev:32432] * parse.y (parser_parse_string, parser_here_document): prevent false error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ parse.y | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index af63917f42..9bb011f4e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Dec 2 22:08:01 2007 Nobuyoshi Nakada + + * parse.y (parser_tokadd_mbchar): fix for ASCII chars. [ruby-dev:32432] + + * parse.y (parser_parse_string, parser_here_document): prevent false + error messages. + Sun Dec 2 20:43:22 2007 Tanaka Akira * re.c (unescape_escaped_nonascii): fix mbclen argument. diff --git a/parse.y b/parse.y index 6e67fd92d2..12d2e8893b 100644 --- a/parse.y +++ b/parse.y @@ -5304,7 +5304,7 @@ static int parser_tokadd_mbchar(struct parser_params *parser, int c) { int len = parser_mbclen(); - if (lex_p + len > lex_pend) { + if (len <= 0 || lex_p + len - 1 > lex_pend) { compile_error(PARSER_ARG "illegal multibyte char"); return -1; } @@ -5491,11 +5491,13 @@ parser_parse_string(struct parser_params *parser, NODE *quote) &enc) == -1) { ruby_sourceline = nd_line(quote); if (func & STR_FUNC_REGEXP) { - compile_error(PARSER_ARG "unterminated regexp meets end of file"); + if (parser->eofp) + compile_error(PARSER_ARG "unterminated regexp meets end of file"); return tREGEXP_END; } else { - compile_error(PARSER_ARG "unterminated string meets end of file"); + if (parser->eofp) + compile_error(PARSER_ARG "unterminated string meets end of file"); return tSTRING_END; } } @@ -5625,6 +5627,7 @@ parser_here_document(struct parser_params *parser, NODE *here) if ((c = nextc()) == -1) { error: compile_error(PARSER_ARG "can't find string \"%s\" anywhere before EOF", eos); + restore: heredoc_restore(lex_strterm); lex_strterm = 0; return 0; @@ -5678,8 +5681,10 @@ parser_here_document(struct parser_params *parser, NODE *here) } do { pushback(c); - if ((c = tokadd_string(func, '\n', 0, NULL, - &enc)) == -1) goto error; + if ((c = tokadd_string(func, '\n', 0, NULL, &enc)) == -1) { + if (parser->eofp) goto error; + goto restore; + } if (c != '\n') { set_yylval_str(STR_NEW3(tok(), toklen(), enc, func)); return tSTRING_CONTENT;