diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-09 07:35:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-09 07:35:31 +0000 |
commit | 64285c599025843bda3c85a0938ee0c73488b14a (patch) | |
tree | f6e18e3fa69eb964915f4d97c8b2dbfb4d99c03d /string.c | |
parent | 7b4486c87774f6318b7bd1cabae5480136357c31 (diff) |
* string.c (rb_str_times): make empty strings to keep taintness,
and a little improvement. [ruby-dev:26900]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -416,17 +416,16 @@ rb_str_times(str, times) long i, len; len = NUM2LONG(times); - if (len == 0) return rb_str_new5(str,0,0); 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'; |