summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-18 00:59:31 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-18 00:59:31 +0000
commita7e8b12f96bcea99a855092e4b200ddfed6c8c41 (patch)
tree23b19636a4f664fb37bab11c3dbf9942bd3a6457
parentd41305b393d1aa33a93dcad15ee1424e24a1a737 (diff)
* sprintf.c (BSD_vfprintf): wrong padding arround prefix and
floating point with %a. [ruby-dev:42403] Bug #3956 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_sprintf.rb7
-rw-r--r--vsnprintf.c3
3 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ccb260b451..af8909e240 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Oct 18 09:57:28 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * sprintf.c (BSD_vfprintf): wrong padding arround prefix and
+ floating point with %a. [ruby-dev:42403] Bug #3956
+
Sun Oct 17 22:36:33 2010 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/delta.rb: added an rdoc tag.
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 96a1b62bb7..9c4566f8d0 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -204,6 +204,13 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("Inf", sprintf("%E", Float::INFINITY))
assert_equal("NaN", sprintf("%e", Float::NAN))
assert_equal("NaN", sprintf("%E", Float::NAN))
+
+ assert_equal(" -0x1p+0", sprintf("%10a", -1))
+ assert_equal(" -0x1.8p+0", sprintf("%10a", -1.5))
+ assert_equal(" -0x1.4p+0", sprintf("%10a", -1.25))
+ assert_equal(" -0x1.2p+0", sprintf("%10a", -1.125))
+ assert_equal(" -0x1.1p+0", sprintf("%10a", -1.0625))
+ assert_equal("-0x1.05p+0", sprintf("%10a", -1.03125))
end
BSIZ = 120
diff --git a/vsnprintf.c b/vsnprintf.c
index a1ac4424a2..1f53bc4265 100644
--- a/vsnprintf.c
+++ b/vsnprintf.c
@@ -829,6 +829,9 @@ fp_begin: _double = va_arg(ap, double);
--expt;
expsize = exponent(expstr, expt, ch + 'p' - 'a');
size = expsize + ndig;
+ size += 2; /* 0x */
+ if (ndig > 1)
+ ++size; /* floating point */
}
else if (ch <= 'e') { /* 'e' or 'E' fmt */
--expt;