Negation was not a good way to handle negative integers; fix #3729

There's a number that negation does not work (-2147483648 in 32bit
environment).
parent b643a1a8
......@@ -860,11 +860,11 @@ retry:
else {
sc = '-';
width--;
v = -v;
}
mrb_assert(base == 10);
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRId, v);
s = nbuf;
if (v < 0) s++; /* skip minus sign */
}
else {
s = nbuf;
......@@ -974,13 +974,12 @@ retry:
if (prec > len) {
CHECK(prec - len);
if (v < 0) {
char c = sign_bits(base, p);
FILL(c, prec - len);
}
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
if ((flags & (FMINUS|FPREC)) != FMINUS) {
char c = '0';
FILL(c, prec - len);
} else if (v < 0) {
char c = sign_bits(base, p);
FILL(c, prec - len);
}
}
PUSH(s, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment