diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 00:56:18 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 00:56:18 +0000 |
commit | f2820af9e0e228fe5182cccab704ce9d83c886c7 (patch) | |
tree | 813964763db6871e32f7c9ce8cc563885c65264e /struct.c | |
parent | 85076a721f82993af073f81e555e5619aa60da45 (diff) | |
download | ruby-f2820af9e0e228fe5182cccab704ce9d83c886c7.tar.gz ruby-f2820af9e0e228fe5182cccab704ce9d83c886c7.tar.xz ruby-f2820af9e0e228fe5182cccab704ce9d83c886c7.zip |
* struct.c (rb_struct_init_copy): disallow changing the size.
[ruby-dev:31168]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@13164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |