From 8f0c1c7d3c44338ea8314e93e9f04fcfc71cb372 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 23 Apr 2016 22:25:33 +0900 Subject: mruby-sprintf:fix double negative signs in printf; fix #3148 MRB_INT_MAX does not have corresponding positive integer --- mrbgems/mruby-sprintf/src/sprintf.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'mrbgems/mruby-sprintf') diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index 1ef96705c..b849b2263 100644 --- a/mrbgems/mruby-sprintf/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -828,18 +828,15 @@ retry: } } 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: -- cgit v1.2.3