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

ruby-changes:34488

From: nobu <ko1@a...>
Date: Fri, 27 Jun 2014 03:42:04 +0900 (JST)
Subject: [ruby-changes:34488] nobu:r46569 (trunk): sprintf.c: unnumbered asterisk with numbered argument

nobu	2014-06-27 03:41:57 +0900 (Fri, 27 Jun 2014)

  New Revision: 46569

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

  Log:
    sprintf.c: unnumbered asterisk with numbered argument
    
    * sprintf.c (GETASTER): should not use the numbered argument to be
      formatted, raise ArgumentError instead.
      [ruby-dev:48330] [Bug #9982]

  Modified files:
    trunk/ChangeLog
    trunk/sprintf.c
    trunk/test/ruby/test_sprintf.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46568)
+++ ChangeLog	(revision 46569)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun 27 03:41:53 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (GETASTER): should not use the numbered argument to be
+	  formatted, raise ArgumentError instead.
+	  [ruby-dev:48330] [Bug #9982]
+
 Thu Jun 26 18:18:28 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/with_different_ofs.rb: move into test library directory.
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 46568)
+++ sprintf.c	(revision 46569)
@@ -79,6 +79,9 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L79
 } while (0)
 
 #define GETARG() (nextvalue != Qundef ? nextvalue : \
+		  GETNEXTARG())
+
+#define GETNEXTARG() ( \
     posarg == -1 ? \
     (rb_raise(rb_eArgError, "unnumbered(%d) mixed with numbered", nextarg), 0) : \
     posarg == -2 ? \
@@ -125,7 +128,7 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L128
 	tmp = GETPOSARG(n); \
     } \
     else { \
-	tmp = GETARG(); \
+	tmp = GETNEXTARG(); \
 	p = t; \
     } \
     (val) = NUM2INT(tmp); \
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 46568)
+++ test/ruby/test_sprintf.rb	(revision 46569)
@@ -184,6 +184,10 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_sprintf.rb#L184
     assert_raise(ArgumentError) { sprintf("%!", 1) }
     assert_raise(ArgumentError) { sprintf("%1$1$d", 1) }
     assert_raise(ArgumentError) { sprintf("%0%") }
+
+    assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$*d", 3) }
+    assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$.*d", 3) }
+
     verbose, $VERBOSE = $VERBOSE, nil
     assert_nothing_raised { sprintf("", 1) }
   ensure

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

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