1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (rb_str_resize): embeds if ptr is null. [ruby-dev:32819]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-12-31 14:27:20 +00:00
parent aaf78dec43
commit de3f2adb53
4 changed files with 23 additions and 9 deletions

View file

@ -1,3 +1,7 @@
Mon Dec 31 23:27:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_resize): embeds if ptr is null. [ruby-dev:32819]
Mon Dec 31 23:17:22 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):

View file

@ -3,11 +3,6 @@
# So all tests will cause failure.
#
assert_normal_exit %q{
null = File.exist?("/dev/null") ? "/dev/null" : "NUL" # maybe DOSISH
File.read(null).clone
}, '[ruby-dev:32819] reported by Kazuhiro NISHIYAMA'
assert_normal_exit %q{
class Foo
def self.add_method

View file

@ -924,25 +924,37 @@ rb_str_set_len(VALUE str, long len)
VALUE
rb_str_resize(VALUE str, long len)
{
long slen;
if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)");
}
rb_str_modify(str);
if (len != RSTRING_LEN(str)) {
slen = RSTRING_LEN(str);
if (len != slen) {
if (STR_EMBED_P(str)) {
char *ptr;
if (len <= RSTRING_EMBED_LEN_MAX) {
STR_SET_EMBED_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
RSTRING(str)->as.ary[len] = '\0';
return str;
}
ptr = ALLOC_N(char,len+1);
MEMCPY(ptr, RSTRING_PTR(str), char, RSTRING_LEN(str));
MEMCPY(ptr, RSTRING(str)->as.ary, char, slen);
RSTRING(str)->as.heap.ptr = ptr;
STR_SET_NOEMBED(str);
}
else if (RSTRING_LEN(str) < len || RSTRING_LEN(str) - len > 1024) {
else if (len <= RSTRING_EMBED_LEN_MAX) {
char *ptr = RSTRING(str)->as.heap.ptr;
STR_SET_EMBED(str);
MEMCPY(RSTRING(str)->as.ary, ptr, char, len);
RSTRING(str)->as.ary[len] = '\0';
STR_SET_EMBED_LEN(str, len);
xfree(ptr);
return str;
}
else if (slen < len || slen - len > 1024) {
REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
}
if (!STR_NOCAPA_P(str)) {

View file

@ -368,6 +368,9 @@ class TestString < Test::Unit::TestCase
assert_equal(a.tainted?, b.tainted?)
end
end
null = File.exist?("/dev/null") ? "/dev/null" : "NUL" # maybe DOSISH
assert_equal("", File.read(null).clone, '[ruby-dev:32819] reported by Kazuhiro NISHIYAMA')
end
def test_concat