summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-25 20:12:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-25 20:12:19 +0000
commit8ca32b6e6e95f650ccb5c8bfcf15bbc9802ac3d0 (patch)
tree547da6fa2ad79bfa6d5c52d3a92999bf870365be
parentb0001e921299e8f443a9d716d1c4367da3279f4d (diff)
* 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@13513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--parse.y29
-rw-r--r--regex.c37
-rw-r--r--version.h6
4 files changed, 55 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 4baa16c..262126b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Sep 26 05:12:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (yyerror): limit error message length. [ruby-dev:31848]
+
+ * regex.c (re_mbc_startpos): separated from re_adjust_startpos.
+
Mon Sep 24 16:52:11 2007 Urabe Shyouhei <shyouhei@ruby-lang.org>
* lib/net/http.rb: fix typo.
diff --git a/parse.y b/parse.y
index 157aefc..f6c6311 100644
--- a/parse.y
+++ b/parse.y
@@ -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';
diff --git a/regex.c b/regex.c
index fa04871..a7a8312 100644
--- a/regex.c
+++ b/regex.c
@@ -3109,6 +3109,28 @@ re_compile_fastmap(bufp)
/* adjust startpos value to the position between characters. */
int
+re_mbc_startpos(string, size, startpos, range)
+ const char *string;
+ int size, startpos, range;
+{
+ int i = mbc_startpos(string, startpos);
+
+ if (i < startpos) {
+ if (range > 0) {
+ startpos = i + mbclen(string[i]);
+ }
+ else {
+ int len = mbclen(string[i]);
+ if (i + len <= startpos)
+ startpos = i + len;
+ else
+ startpos = i;
+ }
+ }
+ return startpos;
+}
+
+int
re_adjust_startpos(bufp, string, size, startpos, range)
struct re_pattern_buffer *bufp;
const char *string;
@@ -3121,20 +3143,7 @@ re_adjust_startpos(bufp, string, size, startpos, range)
/* Adjust startpos for mbc string */
if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
- int i = mbc_startpos(string, startpos);
-
- if (i < startpos) {
- if (range > 0) {
- startpos = i + mbclen(string[i]);
- }
- else {
- int len = mbclen(string[i]);
- if (i + len <= startpos)
- startpos = i + len;
- else
- startpos = i;
- }
- }
+ startpos = re_mbc_startpos(string, size, startpos, range);
}
return startpos;
}
diff --git a/version.h b/version.h
index 3bf0083..368b510 100644
--- a/version.h
+++ b/version.h
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-09-23"
+#define RUBY_RELEASE_DATE "2007-09-26"
#define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20070923
+#define RUBY_RELEASE_CODE 20070926
#define RUBY_PATCHLEVEL 5000
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 23
+#define RUBY_RELEASE_DAY 26
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];