[前][次][番号順一覧][スレッド一覧]

ruby-changes:19813

From: yugui <ko1@a...>
Date: Tue, 31 May 2011 12:59:44 +0900 (JST)
Subject: [ruby-changes:19813] yugui:r31858 (trunk): * strftime.c (rb_strftime_with_timespec): improved style consistency.

yugui	2011-05-31 12:59:36 +0900 (Tue, 31 May 2011)

  New Revision: 31858

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31858

  Log:
    * strftime.c (rb_strftime_with_timespec): improved style consistency.
      constified some variables.
    
    * test/test_time.rb (TestTime#test_huge_precision): test for #4456.

  Modified files:
    trunk/ChangeLog
    trunk/strftime.c
    trunk/test/test_time.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31857)
+++ ChangeLog	(revision 31858)
@@ -1,3 +1,10 @@
+Tue May 31 13:00:17 2011  Yuki Sonoda (Yugui)  <yugui@y...>
+
+	* 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@r...>
 
 	* test/io/wait/test_io_wait.rb (TestIOWait#{test_nread,test_ready?,
Index: strftime.c
===================================================================
--- strftime.c	(revision 31857)
+++ strftime.c	(revision 31858)
@@ -170,8 +170,8 @@
 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)
 {
-	char *endp = s + maxsize;
-	char *start = s;
+	const char *const endp = s + maxsize;
+	const char *const start = s;
 	const char *sp, *tp;
 	auto char tbuf[100];
 	long off;
@@ -237,10 +237,7 @@
 			i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \
 			if (!i) return 0; \
 			if (precision > i) {\
-				if (start + maxsize < s + precision) { \
-					errno = ERANGE; \
-					return 0; \
-				} \
+				NEEDS(precision); \
 				memmove(s + precision - i, s, i);\
 				memset(s, padding ? padding : ' ', precision - i); \
 				s += precision;	\
@@ -618,7 +615,7 @@
 
                                 if (*format == 'G') {
                                         if (FIXNUM_P(yv)) {
-                                                long y = FIX2LONG(yv);
+                                                const long y = FIX2LONG(yv);
                                                 FMT('0', 0 <= y ? 4 : 5, "ld", y);
                                         }
                                         else {
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 31857)
+++ test/test_time.rb	(revision 31858)
@@ -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 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]