Skip to content

Commit

Permalink
mruby-sprintf:fix double negative signs in printf; fix #3148
Browse files Browse the repository at this point in the history
MRB_INT_MAX does not have corresponding positive integer
  • Loading branch information
matz committed Apr 23, 2016
1 parent c522907 commit 8f0c1c7
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions mrbgems/mruby-sprintf/src/sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,18 +828,15 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
}
}
if (sign) {
if (v < 0) {
v = -v;
sc = '-';
width--;
}
else if (flags & FPLUS) {
sc = '+';
width--;
}
else if (flags & FSPACE) {
sc = ' ';
width--;
if (v > 0) {
if (flags & FPLUS) {
sc = '+';
width--;
}
else if (flags & FSPACE) {
sc = ' ';
width--;
}
}
switch (base) {
case 2:
Expand Down

0 comments on commit 8f0c1c7

Please sign in to comment.