summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-28 02:05:54 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-28 02:05:54 (GMT)
commitbe2e146a55e5210a2cf6303d51c91653c5ca14c2 (patch)
tree734f28c3013f2493aebbdfb4bc16273a7f4f0d2f /sprintf.c
parent74a5dc58258aa05b151d0de5002cef7177af1c8a (diff)
sprintf.c: fix one-off bug
* sprintf.c (rb_str_format): `CHECK` just before `FILL_`, but after another `PUSH`. fix one-off bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sprintf.c b/sprintf.c
index fb11a6d..baee759 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -791,7 +791,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
{
volatile VALUE val = GETARG();
int valsign;
- char nbuf[64], *s;
+ char nbuf[BIT_DIGITS(SIZEOF_LONG*CHAR_BIT)+2], *s;
const char *prefix = 0;
int sign = 0, dots = 0;
char sc = 0;
@@ -1014,9 +1014,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
int plen = (int)strlen(prefix);
PUSH(prefix, plen);
}
- CHECK(prec - len);
if (dots) PUSH("..", 2);
if (prec > len) {
+ CHECK(prec - len);
if (!sign && valsign < 0) {
char c = sign_bits(base, p);
FILL_(c, prec - len);
@@ -1073,15 +1073,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (prec >= len) len = prec + 1; /* integer part 0 */
if (sign || (flags&FSPACE)) ++len;
if (prec > 0) ++len; /* period */
- CHECK(len > width ? len : width);
fill = width > len ? width - len : 0;
- if (fill && !(flags&FMINUS) && !(flags&FZERO)) {
+ CHECK(fill + len);
+ if (fill && !(flags&(FMINUS|FZERO))) {
FILL_(' ', fill);
}
if (sign || (flags&FSPACE)) {
buf[blen++] = sign > 0 ? '+' : sign < 0 ? '-' : ' ';
}
- if (fill && !(flags&FMINUS) && (flags&FZERO)) {
+ if (fill && (flags&(FMINUS|FZERO)) == FZERO) {
FILL_('0', fill);
}
len = RSTRING_LEN(val) + zero;