summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb2
-rw-r--r--src/string.c7
-rw-r--r--test/t/string.rb5
3 files changed, 8 insertions, 6 deletions
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index ce4bc7352..2bb32cef3 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -14,6 +14,8 @@ assert('String#getbyte') do
end
assert('String#dump') do
+ ("\1" * 100).dump # should not raise an exception - regress #1210
+ "\0".inspect == "\"\\000\"" and
"foo".dump == "\"foo\""
end
diff --git a/src/string.c b/src/string.c
index 5152eadb3..7ea6844a1 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2438,8 +2438,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;
}
}
diff --git a/test/t/string.rb b/test/t/string.rb
index 945ef890c..2d0804519 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -415,10 +415,7 @@ assert('String#each_byte') do
bytes1 == bytes2
end
-assert('String#dump') do
- ("\1" * 100).dump # should not raise an exception - regress #1210
-end
-
assert('String#inspect') do
("\1" * 100).inspect # should not raise an exception - regress #1210
+ "\0".inspect == "\"\\000\""
end