From bb545e213146685e0cdddb064ecc3b22139e01f9 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 15 Aug 2012 07:23:38 +0000 Subject: [PATCH] sprintf.c: coderange fix * sprintf.c (ruby__sfvwrite): set buffer length and exclude uninitialized garbage to get correct coderange. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ sprintf.c | 1 + test/-ext-/test_printf.rb | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3a8b02737a..719a7d88db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Aug 15 16:23:35 2012 Nobuyoshi Nakada + + * sprintf.c (ruby__sfvwrite): set buffer length and exclude + uninitialized garbage to get correct coderange. + + * sprintf.c (ruby__sfvextra): the result should be infected by the + given strings. + + * sprintf.c (ruby__sfvwrite): set buffer length and exclude + uninitialized garbage to get correct coderange. + Wed Aug 15 16:20:09 2012 Nobuyoshi Nakada * common.mk (ID_H_TARGET): make timestamp file of id.h so that the diff --git a/sprintf.c b/sprintf.c index b41ab9cb39..3642e2153a 100644 --- a/sprintf.c +++ b/sprintf.c @@ -1174,6 +1174,7 @@ ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio) len -= n; } fp->_p = (unsigned char *)buf; + rb_str_set_len(result, buf - RSTRING_PTR(result)); return 0; } diff --git a/test/-ext-/test_printf.rb b/test/-ext-/test_printf.rb index f801030c07..fc4e065345 100644 --- a/test/-ext-/test_printf.rb +++ b/test/-ext-/test_printf.rb @@ -21,4 +21,11 @@ class Test_SPrintf < Test::Unit::TestCase def test_inspect assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self)) end + + def test_encoding + def self.to_s + "\u{3042 3044 3046 3048 304a}" + end + assert_equal("<\u{3042 3044 3046 3048 304a}>", Bug::Printf.s(self)) + end end