From 4c289d8d104fc3cd73858b4dc2bdf13c62f50377 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 12 Jul 2007 08:03:18 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ struct.c | 11 +++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index a45a4c1559..b874557d98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 12 17:03:15 2007 Nobuyoshi Nakada + + * struct.c (rb_struct_init_copy): disallow changing the size. + [ruby-dev:31168] + Thu Jul 12 12:58:21 2007 Koichi Sasada * blockinlining.c: remove "yarv" prefix. 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));