Permalink
Browse files

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...
1 parent 42f22c9 commit 3314262720a8ea948602f6e586deb1778f29ef08 @Watson1978 Watson1978 committed Nov 23, 2010
Showing with 3 additions and 0 deletions.
  1. +3 −0 sprintf.c
View
@@ -549,6 +549,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
break;
case '.':
+ if (precision_flag) {
+ rb_raise(rb_eArgError, "precision given twice");
+ }
zero_flag = false;
precision_flag = true;
if (format_str[++i] == '*') {

0 comments on commit 3314262

Please sign in to comment.