diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 07:17:01 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 07:17:01 +0000 |
commit | 34cc6247c67e8f99ef5927c43dbb9435853943f0 (patch) | |
tree | 14eee8b6a45566a8abc2cc5210050958638ab527 /parse.y | |
parent | 2062a9149e8a4232b08520200b18a393782e87dd (diff) |
merge revision(s) 13513:
* parse.y (yyerror): limit error message length. [ruby-dev:31848]
* regex.c (re_mbc_startpos): separated from re_adjust_startpos.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@16788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -2516,7 +2516,9 @@ static int yyerror(msg) const char *msg; { - char *p, *pe, *buf; + const int max_line_margin = 30; + const char *p, *pe; + char *buf; int len, i; rb_compile_error("%s", msg); @@ -2535,17 +2537,32 @@ yyerror(msg) len = pe - p; if (len > 4) { + char *p2; + const char *pre = "", *post = ""; + + if (len > max_line_margin * 2 + 10) { + int re_mbc_startpos _((const char *, int, int, int)); + if ((len = lex_p - p) > max_line_margin) { + p = p + re_mbc_startpos(p, len, len - max_line_margin, 0); + pre = "..."; + } + if ((len = pe - lex_p) > max_line_margin) { + pe = lex_p + re_mbc_startpos(lex_p, len, max_line_margin, 1); + post = "..."; + } + len = pe - p; + } buf = ALLOCA_N(char, len+2); MEMCPY(buf, p, char, len); buf[len] = '\0'; - rb_compile_error_append("%s", buf); + rb_compile_error_append("%s%s%s", pre, buf, post); i = lex_p - p; - p = buf; pe = p + len; + p2 = buf; pe = buf + len; - while (p < pe) { - if (*p != '\t') *p = ' '; - p++; + while (p2 < pe) { + if (*p2 != '\t') *p2 = ' '; + p2++; } buf[i] = '^'; buf[i+1] = '\0'; |