mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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).
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user