Project

General

Profile

Bug #4457

Time#strftime で %z 指定子などに大きな幅を指定した際の不具合

Added by tadf (tadayoshi funaba) over 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-dev:43285]

Description

=begin
大きな幅を指定すると結果が空になる事があります。

$ ruby -e "p Time.now.strftime('%100000z')"
""
$ ruby -e "p Time.now.strftime('%10z')"
"+000000900"

=end


Related issues

Related to Ruby trunk - Bug #4456: Time#strftime で %F 指定子に大きな幅を指定した際の不具合Closed2011-03-02

Associated revisions

Revision f2f14f57
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 32885
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Revision 32885
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Revision 32885
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Revision 32885
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Revision 32885
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Revision 4a5a6f4a
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

merge revision(s) 32885:

* time.c (rb_strftime_alloc): raise ERANGE if width is too large.
  Patch by Nobuyoshi Nakada. [Bug #4457] 

* test/ruby/test_time.rb (class TestTime): add a test for the
  above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 [ruby-dev:43931] Updated by naruse (Yui NARUSE) almost 7 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)
  • Target version set to 1.9.3

#2 [ruby-dev:44176] Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

  • Category set to core

こちら、状況いかがでしょうか?

#3 [ruby-dev:44182] Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • ruby -v changed from ruby 1.9.3dev (2011-03-02) [i686-linux] to -

なかだです。

At Thu, 21 Jul 2011 13:57:30 +0900,
Motohiro KOSAKI wrote in :

こちら、状況いかがでしょうか?

できなければ例外、ですかねぇ。

diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 38e567a..1f07a82 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -650,6 +650,9 @@ class TestTime < Test::Unit::TestCase

  # 
  assert_equal("3000000000", Time.at(3000000000).strftime('%s'))

+

  • bug4457 = ''
  • assert_raise(Errno::ERANGE, bug4457) {Time.now.strftime('%8192z')}
    end

    def test_delegate
    Modified time.c
    diff --git a/time.c b/time.c
    index dd846a6..6817c75 100644
    --- a/time.c
    +++ b/time.c
    @@ -4325,8 +4325,12 @@ rb_strftime_alloc(char **buf, const char *format,

    • if the buffer is 1024 times bigger than the length of the
    • format string, it's not failing for lack of room. */
  • if (len > 0 || size >= 1024 * flen) break;

  • if (len > 0) break;
    xfree(*buf);

  • if (size >= 1024 * flen) {

  •  rb_sys_fail(format);
    
  •  break;
    
  • }
    }
    return len;
    }

--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦

#4 [ruby-dev:44272] Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

akrさん、nakadaさんのパッチはコミットしてしまっていいのでしょうか?

#5 [ruby-dev:44310] Updated by akr (Akira Tanaka) almost 7 years ago

とりあえずいいような気がします。

しかし、考えてみると strftime の API が腐っているという問題があるわけで、
そして、Ruby 1.9 では OS の strftime を使っていないのだから、
その API につきあう必要はないわけです。

というわけで、バッファが足りなかったときには必要な長さを返すようにするとか
まともな API を用意して使うのがいい気がしますね。

#6 Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32885.
tadayoshi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • time.c (rb_strftime_alloc): raise ERANGE if width is too large.
    Patch by Nobuyoshi Nakada. [Bug #4457]

  • test/ruby/test_time.rb (class TestTime): add a test for the
    above change.

Also available in: Atom PDF