From 30ab36c7dc743d584a1534c5695ba37fbfb1c78e Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 28 Oct 2010 18:04:23 +0000 Subject: [PATCH] * string.c (rb_str_dump): fix expected length. [ruby-core:32935] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 9 ++++----- test/ruby/test_stringchar.rb | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 523278a403..14224497f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Oct 29 03:04:16 2010 Nobuyoshi Nakada + + * string.c (rb_str_dump): fix expected length. [ruby-core:32935] + Thu Oct 28 23:31:39 2010 Koichi Sasada * gc.c (before_gc_sweep, run_final): fix decrement timing of final_num. diff --git a/string.c b/string.c index daabb97a46..683c78c8cc 100644 --- a/string.c +++ b/string.c @@ -4315,12 +4315,11 @@ rb_str_dump(VALUE str) } else { if (u8) { /* \u{NN} */ - char buf[32]; int n = rb_enc_precise_mbclen(p-1, pend, enc); - if (MBCLEN_CHARFOUND_P(n)) { - int cc = rb_enc_mbc_to_codepoint(p-1, pend, enc); - sprintf(buf, "%x", cc); - len += strlen(buf)+4; + if (MBCLEN_CHARFOUND_P(n-1)) { + unsigned int cc = rb_enc_mbc_to_codepoint(p-1, pend, enc); + while (cc >>= 4) len++; + len += 5; p += MBCLEN_CHARFOUND_LEN(n)-1; break; } diff --git a/test/ruby/test_stringchar.rb b/test/ruby/test_stringchar.rb index b70f171c84..44c8634c02 100644 --- a/test/ruby/test_stringchar.rb +++ b/test/ruby/test_stringchar.rb @@ -163,4 +163,19 @@ EOS s.delete!("a-z") assert_equal("BB", s) end + + def test_dump + bug3996 = '[ruby-core:32935]' + Encoding.list.find_all {|enc| enc.ascii_compatible?}.each do |enc| + (0..256).map do |c| + begin + s = c.chr(enc) + rescue RangeError, ArgumentError + break + else + assert_not_match(/\0/, s.dump, bug3996) + end + end + end + end end