summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-28 18:04:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-28 18:04:23 +0000
commit30ab36c7dc743d584a1534c5695ba37fbfb1c78e (patch)
treea2fbabf7aff4bbcda37b2d3dad98aaf024e77f63 /string.c
parent87c0b99446b0aa2265e25d0cf06ba5676e1683a9 (diff)
downloadruby-30ab36c7dc743d584a1534c5695ba37fbfb1c78e.tar.gz
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c9
1 files changed, 4 insertions, 5 deletions
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;
}