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
commit4c289d8d104fc3cd73858b4dc2bdf13c62f50377 (patch)
tree19995ea9a1d6a73c2aa0b38e30a35c9aae7b2c29 /struct.c
parent6b6bf4dd481f744faf54b5efcda5f32e4565bd7d (diff)
* struct.c (rb_struct_init_copy): disallow changing the size.
[ruby-dev:31168] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/struct.c b/struct.c
index dba4026362..347b864a9b 100644
--- a/struct.c
+++ b/struct.c
@@ -226,7 +226,7 @@ rb_struct_define(const char *name, ...)
ary = rb_ary_new();
va_start(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));
}
@@ -515,13 +515,8 @@ rb_struct_init_copy(VALUE copy, VALUE s)
if (!rb_obj_is_instance_of(s, rb_obj_class(copy))) {
rb_raise(rb_eTypeError, "wrong argument class");
}
- if (0 < RSTRUCT_LEN(s) && RSTRUCT_LEN(s) <= RSTRUCT_EMBED_LEN_MAX) {
- RBASIC(copy)->flags &= ~RSTRUCT_EMBED_LEN_MASK;
- RBASIC(copy)->flags |= RSTRUCT_LEN(s) << RSTRUCT_EMBED_LEN_SHIFT;
- }
- else {
- RSTRUCT(copy)->as.heap.ptr = ALLOC_N(VALUE, RSTRUCT_LEN(s));
- RSTRUCT(copy)->as.heap.len = RSTRUCT_LEN(s);
+ if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
+ rb_raise(rb_eTypeError, "struct size mismatch");
}
MEMCPY(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), VALUE, RSTRUCT_LEN(copy));