[macruby-changes] [4932] MacRuby/trunk/sprintf.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 22 17:51:06 PST 2010


Revision: 4932
          http://trac.macosforge.org/projects/ruby/changeset/4932
Author:   watson1978 at gmail.com
Date:     2010-11-22 17:51:04 -0800 (Mon, 22 Nov 2010)
Log Message:
-----------
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
}}}

Modified Paths:
--------------
    MacRuby/trunk/sprintf.c

Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c	2010-11-23 01:14:26 UTC (rev 4931)
+++ MacRuby/trunk/sprintf.c	2010-11-23 01:51:04 UTC (rev 4932)
@@ -549,6 +549,9 @@
 		    break;
 
 		case '.':
+		    if (precision_flag) {
+			rb_raise(rb_eArgError, "precision given twice");
+		    }
 		    zero_flag = false;
 		    precision_flag = true;
 		    if (format_str[++i] == '*') {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101122/eec78270/attachment.html>


More information about the macruby-changes mailing list