summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-09 07:35:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-09 07:35:31 +0000
commit109451716a482c0fe8e505223e5af0abb951f32b (patch)
treed18c01902ef79e64476ab57ffa745a0be851ae77 /string.c
parent4d0675afac3f977c5438b50c74171bc1611e28b1 (diff)
downloadruby-109451716a482c0fe8e505223e5af0abb951f32b.tar.gz
ruby-109451716a482c0fe8e505223e5af0abb951f32b.tar.xz
ruby-109451716a482c0fe8e505223e5af0abb951f32b.zip
* string.c (rb_str_times): make empty strings to keep taintness,
and a little improvement. [ruby-dev:26900] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/string.c b/string.c
index 363600662..c17f34baa 100644
--- a/string.c
+++ b/string.c
@@ -412,13 +412,13 @@ rb_str_times(str, times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (LONG_MAX/len < RSTRING(str)->len) {
+ if (len && LONG_MAX/len < RSTRING(str)->len) {
rb_raise(rb_eArgError, "argument too big");
}
- str2 = rb_str_new5(str,0, RSTRING(str)->len*len);
- for (i=0; i<len; i++) {
- memcpy(RSTRING(str2)->ptr+(i*RSTRING(str)->len),
+ str2 = rb_str_new5(str,0, len *= RSTRING(str)->len);
+ for (i = 0; i < len; i += RSTRING(str)->len) {
+ memcpy(RSTRING(str2)->ptr + i,
RSTRING(str)->ptr, RSTRING(str)->len);
}
RSTRING(str2)->ptr[RSTRING(str2)->len] = '\0';