From 83d9e9f42e1f704dd5a412b32d9264403d0b488a Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 24 Jan 2010 05:22:51 +0000 Subject: [PATCH] * string.c (rb_str_inspect): increment by rb_enc_mbminlen(enc) for broken byte sequence. [ruby-core:27748] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 3 ++- string.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87f22ba702..5e58c5a597 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ -Sun Jan 24 13:55:54 2010 Tanaka Akira +Sun Jan 24 14:21:48 2010 Tanaka Akira * string.c (rb_enc_strlen_cr): increment by rb_enc_mbminlen(enc) for broken byte sequence. [ruby-core:27748] + (rb_str_inspect): ditto. Sun Jan 24 05:18:34 2010 Nobuyoshi Nakada diff --git a/string.c b/string.c index 6addc621ee..f04802f3f7 100644 --- a/string.c +++ b/string.c @@ -4099,9 +4099,14 @@ rb_str_inspect(VALUE str) n = rb_enc_precise_mbclen(p, pend, enc); if (!MBCLEN_CHARFOUND_P(n)) { if (p > prev) str_buf_cat(result, prev, p - prev); - snprintf(buf, CHAR_ESC_LEN, "\\x%02X", *p & 0377); - str_buf_cat(result, buf, strlen(buf)); - prev = ++p; + n = rb_enc_mbminlen(enc); + if (pend < p + n) + n = pend - p; + while (n--) { + snprintf(buf, CHAR_ESC_LEN, "\\x%02X", *p & 0377); + str_buf_cat(result, buf, strlen(buf)); + prev = ++p; + } continue; } n = MBCLEN_CHARFOUND_LEN(n);