diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-15 08:28:12 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-15 08:28:12 +0000 |
commit | a160986d90cf90a86e01d60eddb04ffe0e584c36 (patch) | |
tree | 5057fae6065134cb2195a5f9b824a55ed29987b4 /sprintf.c | |
parent | ccaf61d5aff59f5e11a772c4f9bd0d1c10232e25 (diff) |
* sprintf.c (rb_str_format): fix: sprintf with hex format and
precision includes wrong dots.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -844,7 +844,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } else { s = nbuf; - if (v < 0) { + if (v < 0 && !(flags & FPREC0)) { dots = 1; } snprintf(fbuf, sizeof(fbuf), "%%l%c", *p == 'X' ? 'x' : *p); @@ -892,7 +892,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val)); s = RSTRING_PTR(tmp); if (*s == '-') { - dots = 1; + if (!(flags & FPREC0)) + dots = 1; if (base == 10) { rb_warning("negative number for %%u specifier"); } @@ -925,14 +926,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } } if (prefix && !prefix[1]) { /* octal */ - if (dots) { - prefix = 0; - } - else if (len == 1 && *s == '0') { + if (len == 1 && *s == '0') { len = 0; if (flags & FPREC) prec--; } - else if ((flags & FPREC) && (prec > len)) { + else if ((flags & FPREC) && (prec > len) && v >= 0) { prefix = 0; } } |