Project

General

Profile

Actions

Bug #4457

closed

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

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

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-dev:43285]

Description

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

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

=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4456: Time#strftime で %F 指定子に大きな幅を指定した際の不具合Closedngoto (Naohisa Goto)03/02/2011Actions

Updated by naruse (Yui NARUSE) over 13 years ago

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

Updated by kosaki (Motohiro KOSAKI) over 13 years ago

  • Category set to core

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

Updated by nobu (Nobuyoshi Nakada) over 13 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 [ruby-dev:44176]:

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

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


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

  # [ruby-core:33985]
  assert_equal("3000000000", Time.at(3000000000).strftime('%s'))
  • bug4457 = '[ruby-dev:43285]'
  • 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はできる。
中田 伸悦

Updated by kosaki (Motohiro KOSAKI) over 13 years ago

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

Updated by akr (Akira Tanaka) over 13 years ago

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

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

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

Actions #6

Updated by kosaki (Motohiro KOSAKI) over 13 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] [ruby-dev:43285]

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0