summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-04 07:09:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-04 07:09:47 +0000
commit99d96a89ce57edc4de2ff1acb1d4ed7737144140 (patch)
tree631d00abf185287dc0b6b72f53083cf2a65824e9
parentc37b2ef8dcb88bc7a60e254bfc4f8f19279fe45e (diff)
downloadruby-99d96a89ce57edc4de2ff1acb1d4ed7737144140.tar.gz
* string.c (rb_str_resize): should copy the content properly. a
patch from Jeremy Evans at [ruby-core:31615]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/-test-/bug-3652/bug.c16
-rw-r--r--ext/-test-/bug-3652/extconf.rb1
-rw-r--r--string.c2
-rw-r--r--test/-ext-/test_bug-3652.rb12
5 files changed, 35 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 076d0586e5..ce180ebc3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Aug 4 16:09:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_resize): should copy the content properly. a
+ patch from Jeremy Evans at [ruby-core:31615].
+
Wed Aug 4 15:47:21 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (create_makefile): no need to create the directory
diff --git a/ext/-test-/bug-3652/bug.c b/ext/-test-/bug-3652/bug.c
new file mode 100644
index 0000000000..290ac2ddee
--- /dev/null
+++ b/ext/-test-/bug-3652/bug.c
@@ -0,0 +1,16 @@
+#include <ruby.h>
+
+static VALUE
+bug_str_resize(VALUE self, VALUE init, VALUE repl)
+{
+ long initlen = NUM2LONG(init);
+ VALUE s = rb_str_buf_new(initlen);
+ return rb_str_resize(s, strlcpy(RSTRING_PTR(s), StringValueCStr(repl), (size_t)initlen));
+}
+
+void
+Init_bug(void)
+{
+ VALUE mBug = rb_define_module("Bug");
+ rb_define_module_function(mBug, "str_resize", bug_str_resize, 2);
+}
diff --git a/ext/-test-/bug-3652/extconf.rb b/ext/-test-/bug-3652/extconf.rb
new file mode 100644
index 0000000000..44f57b41c8
--- /dev/null
+++ b/ext/-test-/bug-3652/extconf.rb
@@ -0,0 +1 @@
+create_makefile("-test-/bug-3652/bug")
diff --git a/string.c b/string.c
index ae88db3761..6d8b606c11 100644
--- a/string.c
+++ b/string.c
@@ -1723,7 +1723,7 @@ rb_str_resize(VALUE str, long len)
else if (len <= RSTRING_EMBED_LEN_MAX) {
char *ptr = RSTRING(str)->as.heap.ptr;
STR_SET_EMBED(str);
- if (slen > 0) MEMCPY(RSTRING(str)->as.ary, ptr, char, len);
+ if (len > 0) MEMCPY(RSTRING(str)->as.ary, ptr, char, len);
RSTRING(str)->as.ary[len] = '\0';
STR_SET_EMBED_LEN(str, len);
if (independent) xfree(ptr);
diff --git a/test/-ext-/test_bug-3652.rb b/test/-ext-/test_bug-3652.rb
new file mode 100644
index 0000000000..0e4d658081
--- /dev/null
+++ b/test/-ext-/test_bug-3652.rb
@@ -0,0 +1,12 @@
+require 'test/unit'
+require '-test-/bug-3652/bug'
+
+class Test_BUG_3652 < Test::Unit::TestCase
+ def test_block_call_id
+ bug3652 = '[ruby-core:31615]'
+ s = "123456789012345678901234"
+ assert_equal(s, Bug.str_resize(127, s), bug3652)
+ s = "123456789"
+ assert_equal(s, Bug.str_resize(127, s), bug3652)
+ end
+end