summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-12 08:03:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-12 08:03:18 +0000
commit420a5fe48efdde608671395bd4eb7583a60d38ef (patch)
tree76dcbcae2108edd7a1d97cf7d6a478451896aca9 /struct.c
parentd7e32900ccde0a07e9912f04595e85795114dde8 (diff)
* struct.c (rb_struct_init_copy): disallow changing the size.
[ruby-dev:31168] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/struct.c b/struct.c
index cdc6efa4b4..88357dedc9 100644
--- a/struct.c
+++ b/struct.c
@@ -252,7 +252,7 @@ rb_struct_define(name, va_alist)
ary = rb_ary_new();
va_init_list(ar, name);
- while (mem = va_arg(ar, char*)) {
+ while ((mem = va_arg(ar, char*)) != 0) {
ID slot = rb_intern(mem);
rb_ary_push(ary, ID2SYM(slot));
}
@@ -557,8 +557,9 @@ rb_struct_init_copy(copy, s)
if (!rb_obj_is_instance_of(s, rb_obj_class(copy))) {
rb_raise(rb_eTypeError, "wrong argument class");
}
- RSTRUCT(copy)->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
- RSTRUCT(copy)->len = RSTRUCT(s)->len;
+ if (RSTRUCT(copy)->len != RSTRUCT(s)->len) {
+ rb_raise(rb_eTypeError, "struct size mismatch");
+ }
MEMCPY(RSTRUCT(copy)->ptr, RSTRUCT(s)->ptr, VALUE, RSTRUCT(copy)->len);
return copy;