aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-17 18:04:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-17 18:04:30 +0000
commit642a2f04b0b866a0c578ff8003a4a4af853d8680 (patch)
treeee0c82d00553324c4e5aff580ed996c7773eb98b /sprintf.c
parent25bd961896647c9e5d6ea110d3c96626555c3795 (diff)
downloadruby-642a2f04b0b866a0c578ff8003a4a4af853d8680.tar.gz
sprintf.c: fix width underflow
* sprintf.c (rb_str_format): fix memory corruption by width underflow. https://github.com/mruby/mruby/issues/3347 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sprintf.c b/sprintf.c
index 5884926b3e..4342904bdc 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -705,10 +705,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
CHECK(n);
rb_enc_mbcput(c, &buf[blen], enc);
blen += n;
- FILL(' ', width-1);
+ if (width > 1) FILL(' ', width-1);
}
else {
- FILL(' ', width-1);
+ if (width > 1) FILL(' ', width-1);
CHECK(n);
rb_enc_mbcput(c, &buf[blen], enc);
blen += n;