summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-25 09:07:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-25 09:07:32 +0000
commit2936600385283d3e320b72ed6a70882805599411 (patch)
tree058477d4c73b52a1dee3635363c5a947a54c7b5d
parentbc02b02778ca73eb64e803216e19650cd224798f (diff)
downloadruby-2936600385283d3e320b72ed6a70882805599411.tar.gz
ruby-2936600385283d3e320b72ed6a70882805599411.tar.xz
ruby-2936600385283d3e320b72ed6a70882805599411.zip
* string.c (rb_str_inspect): don't call rb_enc_codepoint with empty
string. fix '#'.inspect. * encoding.c (rb_enc_codepoint): raise on empty string. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--encoding.c5
-rw-r--r--string.c3
3 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 33739f3e3..ad26d8368 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Dec 25 18:06:04 2007 Tanaka Akira <akr@fsij.org>
+
+ * string.c (rb_str_inspect): don't call rb_enc_codepoint with empty
+ string. fix '#'.inspect.
+
+ * encoding.c (rb_enc_codepoint): raise on empty string.
+
Tue Dec 25 17:48:28 2007 Shugo Maeda <shugo@ruby-lang.org>
* vm.c (rb_frame_method_id_and_class): new function to get the
diff --git a/encoding.c b/encoding.c
index cfa49a512..ee0fdadb3 100644
--- a/encoding.c
+++ b/encoding.c
@@ -662,7 +662,10 @@ rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc)
{
- int r = rb_enc_precise_mbclen(p, e, enc);
+ int r;
+ if (e <= p)
+ rb_raise(rb_eArgError, "empty string");
+ r = rb_enc_precise_mbclen(p, e, enc);
if (MBCLEN_CHARFOUND(r))
return ONIGENC_MBC_TO_CODE(enc,(UChar*)p,(UChar*)e);
else
diff --git a/string.c b/string.c
index 7c49b3463..b06c2f5b8 100644
--- a/string.c
+++ b/string.c
@@ -3025,7 +3025,8 @@ rb_str_inspect(VALUE str)
p += n;
if (c == '"'|| c == '\\' ||
- (c == '#' && (cc = rb_enc_codepoint(p,pend,enc),
+ (c == '#' && p < pend &&
+ (cc = rb_enc_codepoint(p,pend,enc),
(cc == '$' || cc == '@' || cc == '{')))) {
prefix_escape(result, c, enc);
}