summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sprintf.c b/sprintf.c
index 53d2d8bfc4..c54e8e8ad5 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -802,8 +802,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
blen++;
need--;
}
- while (need-- > strlen(expr)) {
- buf[blen++] = '0';
+ if ((need -= strlen(expr)) > 0) {
+ memset(buf+blen, '0', need);
+ blen += need;
}
strncpy(&buf[blen], expr, strlen(expr));
}