From f2820af9e0e228fe5182cccab704ce9d83c886c7 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 22 Aug 2007 00:56:18 +0000 Subject: * 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 --- ChangeLog | 5 +++++ struct.c | 7 ++++--- version.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a9a6fa8f..968e7d77a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Aug 22 09:55:08 2007 Nobuyoshi Nakada + + * struct.c (rb_struct_init_copy): disallow changing the size. + [ruby-dev:31168] + Wed Aug 22 09:54:28 2007 NAKAMURA, Hiroshi * random.c: documentation fix. srand(0) initializes PRNG with '0', diff --git a/struct.c b/struct.c index cdc6efa4b..88357dedc 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; diff --git a/version.h b/version.h index 83a6321b6..724a52b37 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2007-08-22" #define RUBY_VERSION_CODE 186 #define RUBY_RELEASE_CODE 20070822 -#define RUBY_PATCHLEVEL 56 +#define RUBY_PATCHLEVEL 57 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 -- cgit