summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-01 13:07:05 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-01 13:07:05 +0000
commit9ba40029603e4385e47b606a192f6ab8f0b52e41 (patch)
tree0ecdf996793af2c6bb53239323bbc9506cf276fe /string.c
parent85c476a342403499de298ed6e1a5544b4cbdc827 (diff)
* string.c (rb_str_resize): should copy embedded string to
malloc'ed buffer. a patch from <nobu at ruby-lang.org> in [ruby-dev:29369]. fixed: [ruby-dev:29368] * string.c (rb_str_ord): use %ld specifier since STRING_LEN() is a long. [ruby-dev:29369] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/string.c b/string.c
index d28b2da2e1..6482e32c51 100644
--- a/string.c
+++ b/string.c
@@ -682,12 +682,15 @@ rb_str_resize(VALUE str, long len)
rb_str_modify(str);
if (len != RSTRING_LEN(str)) {
if (STR_EMBED_P(str)) {
+ char *ptr;
if (len <= RSTRING_EMBED_LEN_MAX) {
STR_SET_EMBED_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
return str;
}
- RSTRING(str)->as.heap.ptr = ALLOC_N(char,len+1);
+ ptr = ALLOC_N(char,len+1);
+ MEMCPY(ptr, RSTRING(str)->ary, char, RSTRING_LEN(str));
+ RSTRING(str)->as.heap.ptr = ptr;
STR_SET_NOEMBED(str);
}
else if (RSTRING_LEN(str) < len || RSTRING_LEN(str) - len > 1024) {
@@ -4165,7 +4168,7 @@ rb_str_ord(VALUE s)
if (RSTRING_LEN(s) != 1) {
rb_raise(rb_eTypeError,
- "expacted a characer, but string of size %d given",
+ "expacted a characer, but string of size %ld given",
RSTRING_LEN(s));
}
c = RSTRING_PTR(s)[0] & 0xff;