Skip to content
This repository
Browse code

sprintf() will throw an exception when was given precision format twice.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

assert_raise(ArgumentError){ sprintf("%.5.5s", 5) }
assert_raise(ArgumentError){ sprintf("%.5.*s", 5, 5) }
assert_raise(ArgumentError){ sprintf("%.*.5s", 5, 5) }

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4932 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 3314262720a8ea948602f6e586deb1778f29ef08 1 parent 42f22c9
Watson authored November 23, 2010

Showing 1 changed file with 3 additions and 0 deletions. Show diff stats Hide diff stats

  1. 3  sprintf.c
3  sprintf.c
@@ -549,6 +549,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
549 549
 		    break;
550 550
 
551 551
 		case '.':
  552
+		    if (precision_flag) {
  553
+			rb_raise(rb_eArgError, "precision given twice");
  554
+		    }
552 555
 		    zero_flag = false;
553 556
 		    precision_flag = true;
554 557
 		    if (format_str[++i] == '*') {

0 notes on commit 3314262

Please sign in to comment.
Something went wrong with that request. Please try again.