aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-23 01:04:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-23 01:04:39 +0000
commitdac4385dfdc7df4a36af93f1a2f5ef6a22d773dc (patch)
tree81c4f7ff4b02bab28c347e5dc19061276ff9f18c /sprintf.c
parent98e086327dc6da7cd23a5fb8d60a70b4fbd480b3 (diff)
downloadruby-dac4385dfdc7df4a36af93f1a2f5ef6a22d773dc.tar.gz
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 92738783eb..c8522ddf4b 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));
}