From 6b47d60e1681d643710ef0c1462539cfdcea9877 Mon Sep 17 00:00:00 2001 From: yugui Date: Sat, 28 May 2011 23:31:44 +0000 Subject: [PATCH] * strftime.c (STRFTIME): return 0 and ERANGE when precision is too large. [ruby-dev:43284] fixes #4456 based on r31011. * test/test_time.rb (TestTime#test_huge_precision): test for #4456. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ strftime.c | 1 + test/test_time.rb | 6 ++++++ version.h | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e23504705f..e5e081109f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat May 14 12:20:22 2011 Yuki Sonoda (Yugui) + + * strftime.c (STRFTIME): return 0 and ERANGE when precision is too + large. [ruby-dev:43284] fixes #4456 + based on r31011. + + * test/test_time.rb (TestTime#test_huge_precision): test for #4456. + Sat Feb 26 07:10:05 2011 Aaron Patterson * ext/psych/lib/psych/scalar_scanner.rb: fix parsing timezone's whose diff --git a/strftime.c b/strftime.c index 2b98e29148..3c32d09d99 100644 --- a/strftime.c +++ b/strftime.c @@ -309,6 +309,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str i = rb_strftime_with_timespec(s, endp - s, fmt, vtm, timev, ts, gmt); \ if (!i) return 0; \ if (precision > i) {\ + NEEDS(precision); \ memmove(s + precision - i, s, i);\ memset(s, padding ? padding : ' ', precision - i); \ s += precision; \ diff --git a/test/test_time.rb b/test/test_time.rb index d8468c6c43..d3f3c22dff 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -1,5 +1,6 @@ require 'time' require 'test/unit' +require_relative 'ruby/envutil.rb' class TestTimeExtension < Test::Unit::TestCase # :nodoc: def test_rfc822 @@ -397,4 +398,9 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc: assert_equal(123456789, Time.xmlschema("2000-01-01T00:00:00.123456789+00:00").tv_nsec) assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec) end + + def test_huge_precision + bug4456 = '[ruby-dev:43284]' + assert_normal_exit %q{ Time.now.strftime("%1000000000F") }, bug4456 + end end diff --git a/version.h b/version.h index 705040392f..5f437e3f86 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 208 +#define RUBY_PATCHLEVEL 209 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1