From da4b3d1c2cbcee672ec07760cf58b850213aa02a Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Thu, 25 Apr 2013 15:28:25 +0900 Subject: Move regression test as String#dump is not in ther core but the mrbgems. --- mrbgems/mruby-string-ext/test/string.rb | 1 + test/t/string.rb | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb index ce4bc7352..e20a2d3f3 100644 --- a/mrbgems/mruby-string-ext/test/string.rb +++ b/mrbgems/mruby-string-ext/test/string.rb @@ -14,6 +14,7 @@ assert('String#getbyte') do end assert('String#dump') do + ("\1" * 100).dump # should not raise an exception - regress #1210 "foo".dump == "\"foo\"" end diff --git a/test/t/string.rb b/test/t/string.rb index 945ef890c..1e0d44f67 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -415,10 +415,6 @@ 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 end -- cgit v1.2.3 From 433cb13e6db6c4f6761613bd0096f5d2f43f4626 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Thu, 25 Apr 2013 15:34:56 +0900 Subject: Add tests to make sure. As we do not use standard library for formatting. --- mrbgems/mruby-string-ext/test/string.rb | 1 + test/t/string.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb index e20a2d3f3..2bb32cef3 100644 --- a/mrbgems/mruby-string-ext/test/string.rb +++ b/mrbgems/mruby-string-ext/test/string.rb @@ -15,6 +15,7 @@ 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/test/t/string.rb b/test/t/string.rb index 1e0d44f67..2d0804519 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -417,4 +417,5 @@ end assert('String#inspect') do ("\1" * 100).inspect # should not raise an exception - regress #1210 + "\0".inspect == "\"\\000\"" end -- cgit v1.2.3 From 6684b7d1cff9eabf71fc0eea2ad06288f7c56afd Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Thu, 25 Apr 2013 15:36:19 +0900 Subject: Remove sprintf(). --- src/string.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; } } -- cgit v1.2.3