* parse.y (parser_yyerror): limit error message length.

[ruby-dev:31848]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-09-25 20:12:24 +00:00
Родитель 2f6f2bfb02
Коммит 52866db1fe
3 изменённых файлов: 24 добавлений и 5 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Sep 26 05:12:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parser_yyerror): limit error message length.
[ruby-dev:31848]
Tue Sep 25 15:11:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Sep 25 15:11:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_ungetc): reallocate internal buffer if pushing data * io.c (io_ungetc): reallocate internal buffer if pushing data

18
parse.y
Просмотреть файл

@ -4572,6 +4572,7 @@ static int
parser_yyerror(struct parser_params *parser, const char *msg) parser_yyerror(struct parser_params *parser, const char *msg)
{ {
#ifndef RIPPER #ifndef RIPPER
const int max_line_margin = 30;
const char *p, *pe; const char *p, *pe;
char *buf; char *buf;
int len, i; int len, i;
@ -4593,10 +4594,23 @@ parser_yyerror(struct parser_params *parser, const char *msg)
len = pe - p; len = pe - p;
if (len > 4) { if (len > 4) {
char *p2; char *p2;
const char *pre = "", *post = "";
if (len > max_line_margin * 2 + 10) {
if (lex_p - p > max_line_margin) {
p = rb_enc_prev_char(p, lex_p - max_line_margin, rb_enc_get(lex_lastline));
pre = "...";
}
if (pe - lex_p > max_line_margin) {
pe = rb_enc_prev_char(lex_p, lex_p + max_line_margin, rb_enc_get(lex_lastline));
post = "...";
}
len = pe - p;
}
buf = ALLOCA_N(char, len+2); buf = ALLOCA_N(char, len+2);
MEMCPY(buf, p, char, len); MEMCPY(buf, p, char, len);
buf[len] = '\0'; buf[len] = '\0';
rb_compile_error_append("%s", buf); rb_compile_error_append("%s%s%s", pre, buf, post);
i = lex_p - p; i = lex_p - p;
p2 = buf; pe = buf + len; p2 = buf; pe = buf + len;
@ -4607,7 +4621,7 @@ parser_yyerror(struct parser_params *parser, const char *msg)
} }
buf[i] = '^'; buf[i] = '^';
buf[i+1] = '\0'; buf[i+1] = '\0';
rb_compile_error_append("%s", buf); rb_compile_error_append("%s%s", pre, buf);
} }
#else #else
dispatch1(parse_error, STR_NEW2(msg)); dispatch1(parse_error, STR_NEW2(msg));

Просмотреть файл

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0" #define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-09-25" #define RUBY_RELEASE_DATE "2007-09-26"
#define RUBY_VERSION_CODE 190 #define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070925 #define RUBY_RELEASE_CODE 20070926
#define RUBY_PATCHLEVEL 0 #define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0 #define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 9 #define RUBY_RELEASE_MONTH 9
#define RUBY_RELEASE_DAY 25 #define RUBY_RELEASE_DAY 26
#ifdef RUBY_EXTERN #ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];