summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-sprintf/src/sprintf.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-04-23 22:25:33 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-04-23 23:50:01 +0900
commit8f0c1c7d3c44338ea8314e93e9f04fcfc71cb372 (patch)
treed6e1524adb62455732e4238cc0a5330aeceb7f12 /mrbgems/mruby-sprintf/src/sprintf.c
parentc5229074bb5d6ad426e968bb5e4a6bf38abdf059 (diff)
downloadmruby-8f0c1c7d3c44338ea8314e93e9f04fcfc71cb372.tar.gz
mruby-8f0c1c7d3c44338ea8314e93e9f04fcfc71cb372.zip
mruby-sprintf:fix double negative signs in printf; fix #3148
MRB_INT_MAX does not have corresponding positive integer
Diffstat (limited to 'mrbgems/mruby-sprintf/src/sprintf.c')
-rw-r--r--mrbgems/mruby-sprintf/src/sprintf.c21
1 files changed, 9 insertions, 12 deletions
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: