ruby-changes:34530
From: nagachika <ko1@a...>
Date: Mon, 30 Jun 2014 02:17:29 +0900 (JST)
Subject: [ruby-changes:34530] nagachika:r46611 (ruby_2_1): merge revision(s) r46098: [Backport #9861]
nagachika 2014-06-30 02:17:20 +0900 (Mon, 30 Jun 2014) New Revision: 46611 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46611 Log: merge revision(s) r46098: [Backport #9861] * vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of `memchr` is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/ext/-test-/printf/printf.c branches/ruby_2_1/test/-ext-/test_printf.rb branches/ruby_2_1/version.h branches/ruby_2_1/vsnprintf.c Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 46610) +++ ruby_2_1/ChangeLog (revision 46611) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Mon Jun 30 02:10:34 2014 Nobuyoshi Nakada <nobu@r...> + + * vsnprintf.c (BSD_vfprintf): fix string width when precision is + given. as the result of `memchr` is NULL or its offset from the + start cannot exceed the size, the comparison was always false. + [ruby-core:62737] [Bug #9861] + Mon Jun 30 01:46:19 2014 Nobuyoshi Nakada <nobu@r...> * ext/fiddle/extconf.rb: supply 0 to fill RUBY_LIBFFI_MODVERSION Index: ruby_2_1/vsnprintf.c =================================================================== --- ruby_2_1/vsnprintf.c (revision 46610) +++ ruby_2_1/vsnprintf.c (revision 46611) @@ -999,7 +999,7 @@ fp_begin: _double = va_arg(ap, double); https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vsnprintf.c#L999 */ const char *p = (char *)memchr(cp, 0, prec); - if (p != NULL && (p - cp) > prec) + if (p != NULL && (p - cp) < prec) size = (int)(p - cp); else size = prec; Index: ruby_2_1/ext/-test-/printf/printf.c =================================================================== --- ruby_2_1/ext/-test-/printf/printf.c (revision 46610) +++ ruby_2_1/ext/-test-/printf/printf.c (revision 46611) @@ -42,18 +42,23 @@ utoa(char *p, char *e, unsigned int x) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/-test-/printf/printf.c#L42 static VALUE printf_test_call(int argc, VALUE *argv, VALUE self) { - VALUE opt, type, num; + VALUE opt, type, num, result; char format[sizeof(int) * 6 + 8], *p = format, cnv; int n; + const char *s; rb_scan_args(argc, argv, "2:", &type, &num, &opt); Check_Type(type, T_STRING); if (RSTRING_LEN(type) != 1) rb_raise(rb_eArgError, "wrong length(%ld)", RSTRING_LEN(type)); switch (cnv = RSTRING_PTR(type)[0]) { - case 'd': case 'x': case 'o': case 'X': break; + case 'd': case 'x': case 'o': case 'X': + n = NUM2INT(num); + break; + case 's': + s = StringValueCStr(num); + break; default: rb_raise(rb_eArgError, "wrong conversion(%c)", cnv); } - n = NUM2INT(num); *p++ = '%'; if (!NIL_P(opt)) { VALUE v; @@ -84,8 +89,13 @@ printf_test_call(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/-test-/printf/printf.c#L89 } *p++ = cnv; *p++ = '\0'; - return rb_assoc_new(rb_enc_sprintf(rb_usascii_encoding(), format, n), - rb_usascii_str_new_cstr(format)); + if (cnv == 's') { + result = rb_enc_sprintf(rb_usascii_encoding(), format, s); + } + else { + result = rb_enc_sprintf(rb_usascii_encoding(), format, n); + } + return rb_assoc_new(result, rb_usascii_str_new_cstr(format)); } void Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 46610) +++ ruby_2_1/version.h (revision 46611) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-06-30" -#define RUBY_PATCHLEVEL 148 +#define RUBY_PATCHLEVEL 149 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_1/test/-ext-/test_printf.rb =================================================================== --- ruby_2_1/test/-ext-/test_printf.rb (revision 46610) +++ ruby_2_1/test/-ext-/test_printf.rb (revision 46611) @@ -181,4 +181,10 @@ class Test_SPrintf < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/-ext-/test_printf.rb#L181 zero: zr, width: width, prec: prec)) } + + def test_string_prec + assert_equal("a", Bug::Printf.("s", "a", prec: 3)[0]) + assert_equal(" a", Bug::Printf.("s", "a", width: 3, prec: 3)[0]) + assert_equal("a ", Bug::Printf.("s", "a", minus: true, width: 3, prec: 3)[0]) + end end Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r46098 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/