diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-04-08 01:13:03 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-04-08 01:13:03 +0900 |
commit | 2f1895fa15386fb3cdc91c5604171290828b9da8 (patch) | |
tree | 464b3a898c0d2a395f7e07424ac12890bde0b888 | |
parent | 1711258144cf7bb4ddeba4a17da70935d5eedb2b (diff) |
Fixed formatted substring expansion [Bug #16767]
-rw-r--r-- | strftime.c | 2 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/strftime.c b/strftime.c index 911bcdaf15..15e29e0b7c 100644 --- a/strftime.c +++ b/strftime.c @@ -331,7 +331,9 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, s += len; \ if (i > 0) case_conv(s, i, flags); \ if (precision > i) {\ + s += i; \ NEEDS(precision); \ + s -= i; \ memmove(s + precision - i, s, i);\ memset(s, padding ? padding : ' ', precision - i); \ s += precision; \ diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 785376f09c..247bc34de7 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -893,6 +893,13 @@ class TestTime < Test::Unit::TestCase assert_equal(8192, Time.now.strftime('%8192z').size) end + def test_strftime_wide_precision + t2000 = get_t2000 + s = t2000.strftime("%28c") + assert_equal(28, s.size) + assert_equal(t2000.strftime("%c"), s.strip) + end + def test_strfimte_zoneoffset t2000 = get_t2000 t = t2000.getlocal("+09:00:00") |