summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/string.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/string.c b/src/string.c
index 5152eadb3..371d3faf6 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2348,12 +2348,10 @@ mrb_str_dump(mrb_state *mrb, mrb_value str)
*q++ = c;
}
else {
- int oct = c & 0xff;
-
*q++ = '\\';
- q[2] = '0' + oct % 8; oct /= 8;
- q[1] = '0' + oct % 8; oct /= 8;
- q[0] = '0' + oct % 8;
+ q[2] = '0' + c % 8; c /= 8;
+ q[1] = '0' + c % 8; c /= 8;
+ q[0] = '0' + c % 8;
q += 3;
}
}
@@ -2438,8 +2436,11 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str)
continue;
}
else {
- int n = sprintf(buf, "\\%03o", c & 0377);
- mrb_str_buf_cat(mrb, result, buf, n);
+ buf[0] = '\\';
+ buf[3] = '0' + c % 8; c /= 8;
+ buf[2] = '0' + c % 8; c /= 8;
+ buf[1] = '0' + c % 8;
+ mrb_str_buf_cat(mrb, result, buf, 4);
continue;
}
}