summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/string.c b/string.c
index 6deb912921..fe7516892b 100644
--- a/string.c
+++ b/string.c
@@ -2718,8 +2718,8 @@ rb_str_inspect(str)
p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
while (p < pend) {
char c = *p++;
- if (ismbchar(c) && p < pend) {
- int len = mbclen(c);
+ int len;
+ if (ismbchar(c) && p + (len = mbclen(c)) <= pend) {
rb_str_buf_cat(result, p - 1, len);
p += len - 1;
}