* strftime.c (rb_strftime_with_timespec): improved style consistency.
constified some variables. * test/test_time.rb (TestTime#test_huge_precision): test for #4456. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69dcd16351
commit
8fa30bbd48
@ -1,3 +1,10 @@
|
|||||||
|
Tue May 31 13:00:17 2011 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
|
* strftime.c (rb_strftime_with_timespec): improved style consistency.
|
||||||
|
constified some variables.
|
||||||
|
|
||||||
|
* test/test_time.rb (TestTime#test_huge_precision): test for #4456.
|
||||||
|
|
||||||
Tue May 31 12:53:10 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue May 31 12:53:10 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* test/io/wait/test_io_wait.rb (TestIOWait#{test_nread,test_ready?,
|
* test/io/wait/test_io_wait.rb (TestIOWait#{test_nread,test_ready?,
|
||||||
|
11
strftime.c
11
strftime.c
@ -170,8 +170,8 @@ max(int a, int b)
|
|||||||
static size_t
|
static size_t
|
||||||
rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
|
rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
|
||||||
{
|
{
|
||||||
char *endp = s + maxsize;
|
const char *const endp = s + maxsize;
|
||||||
char *start = s;
|
const char *const start = s;
|
||||||
const char *sp, *tp;
|
const char *sp, *tp;
|
||||||
auto char tbuf[100];
|
auto char tbuf[100];
|
||||||
long off;
|
long off;
|
||||||
@ -237,10 +237,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); \
|
i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \
|
||||||
if (!i) return 0; \
|
if (!i) return 0; \
|
||||||
if (precision > i) {\
|
if (precision > i) {\
|
||||||
if (start + maxsize < s + precision) { \
|
NEEDS(precision); \
|
||||||
errno = ERANGE; \
|
|
||||||
return 0; \
|
|
||||||
} \
|
|
||||||
memmove(s + precision - i, s, i);\
|
memmove(s + precision - i, s, i);\
|
||||||
memset(s, padding ? padding : ' ', precision - i); \
|
memset(s, padding ? padding : ' ', precision - i); \
|
||||||
s += precision; \
|
s += precision; \
|
||||||
@ -618,7 +615,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str
|
|||||||
|
|
||||||
if (*format == 'G') {
|
if (*format == 'G') {
|
||||||
if (FIXNUM_P(yv)) {
|
if (FIXNUM_P(yv)) {
|
||||||
long y = FIX2LONG(yv);
|
const long y = FIX2LONG(yv);
|
||||||
FMT('0', 0 <= y ? 4 : 5, "ld", y);
|
FMT('0', 0 <= y ? 4 : 5, "ld", y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require 'time'
|
require 'time'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require_relative 'ruby/envutil.rb'
|
||||||
|
|
||||||
class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
||||||
def test_rfc822
|
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.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)
|
assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_huge_precision
|
||||||
|
bug4456 = '[ruby-dev:43284]'
|
||||||
|
assert_normal_exit %q{ Time.now.strftime("%1000000000F") }, bug4456
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user