ruby-changes:16855
From: nobu <ko1@a...>
Date: Wed, 4 Aug 2010 16:12:25 +0900 (JST)
Subject: [ruby-changes:16855] Ruby:r28851 (trunk): * string.c (rb_str_resize): should copy the content properly. a
nobu 2010-08-04 16:09:47 +0900 (Wed, 04 Aug 2010) New Revision: 28851 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28851 Log: * string.c (rb_str_resize): should copy the content properly. a patch from Jeremy Evans at [ruby-core:31615]. Added directories: trunk/ext/-test-/bug-3652/ Added files: trunk/ext/-test-/bug-3652/bug.c trunk/ext/-test-/bug-3652/extconf.rb trunk/test/-ext-/test_bug-3652.rb Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 28850) +++ ChangeLog (revision 28851) @@ -1,3 +1,8 @@ +Wed Aug 4 16:09:43 2010 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * lib/mkmf.rb (create_makefile): no need to create the directory Index: string.c =================================================================== --- string.c (revision 28850) +++ string.c (revision 28851) @@ -1723,7 +1723,7 @@ 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); Index: ext/-test-/bug-3652/extconf.rb =================================================================== --- ext/-test-/bug-3652/extconf.rb (revision 0) +++ ext/-test-/bug-3652/extconf.rb (revision 28851) @@ -0,0 +1 @@ +create_makefile("-test-/bug-3652/bug") Property changes on: ext/-test-/bug-3652/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/bug-3652/bug.c =================================================================== --- ext/-test-/bug-3652/bug.c (revision 0) +++ ext/-test-/bug-3652/bug.c (revision 28851) @@ -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); +} Property changes on: ext/-test-/bug-3652/bug.c ___________________________________________________________________ Added: svn:eol-style + LF Index: test/-ext-/test_bug-3652.rb =================================================================== --- test/-ext-/test_bug-3652.rb (revision 0) +++ test/-ext-/test_bug-3652.rb (revision 28851) @@ -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 Property changes on: test/-ext-/test_bug-3652.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/