summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-06 02:12:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-06 02:12:31 +0000
commit6b10829b22b2919fb8e8cea895c5fb56c3760127 (patch)
tree480cfd0753a14cad4923e19abdb4ca1909b15368
parentbececd35c5e177de014a0faf83da03db119a825c (diff)
* sprintf.c (rb_str_format): no need of loop.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--sprintf.c5
2 files changed, 7 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 96047190e5..11fc68e67b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Mar 6 11:12:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * sprintf.c (rb_str_format): no need of loop.
+
Thu Mar 6 08:30:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_mod_freeze): call rb_class_name() directly.
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));
}