summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-23 01:04:39 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-23 01:04:39 (GMT)
commit6f8f950cc3aec12826c72e7e67bf54022444aacc (patch)
tree81c4f7ff4b02bab28c347e5dc19061276ff9f18c /sprintf.c
parenta6f0ec21e9d07a7a10f5a2fe06728fdad5b4d1d6 (diff)
Fix space flag when Inf/NaN and width==3
* sprintf.c (rb_str_format): while `"% 2f"` and `"% 4f"` result in `" Inf"` and `" Inf"` respectively, `"% 3f"` results in `"Inf"` (no space). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/sprintf.c b/sprintf.c
index 9273878..c8522dd 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1136,7 +1136,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
expr = "Inf";
}
need = (int)strlen(expr);
- if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS))
+ if ((!isnan(fval) && fval < 0.0) || (flags & (FPLUS|FSPACE)))
need++;
if ((flags & FWIDTH) && need < width)
need = width;
@@ -1157,8 +1157,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
buf[blen + need - strlen(expr) - 1] = '-';
else if (flags & FPLUS)
buf[blen + need - strlen(expr) - 1] = '+';
- else if ((flags & FSPACE) && need > width)
- blen++;
memcpy(&buf[blen + need - strlen(expr)], expr,
strlen(expr));
}