summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-struct
diff options
context:
space:
mode:
authormattn <[email protected]>2013-03-01 17:45:49 +0900
committermattn <[email protected]>2013-03-01 17:45:49 +0900
commit99a6de063cc4c4964074b27ad21553043b468368 (patch)
tree53683a8f1f24e9520a3af89823c88b97362f470b /mrbgems/mruby-struct
parentcb2de0907a08f985c740f711c274c175217fccb9 (diff)
downloadmruby-99a6de063cc4c4964074b27ad21553043b468368.tar.gz
mruby-99a6de063cc4c4964074b27ad21553043b468368.zip
Set nil to uninitialized members
Diffstat (limited to 'mrbgems/mruby-struct')
-rw-r--r--mrbgems/mruby-struct/src/struct.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index c306bc7d9..5b7d0ab5d 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -431,7 +431,7 @@ static mrb_value
mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_value self)
{
struct RClass *klass = mrb_obj_class(mrb, self);
- int n;
+ int i, n;
struct RStruct *st;
n = num_members(mrb, klass);
@@ -442,6 +442,9 @@ mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_val
DATA_PTR(self) = st;
DATA_TYPE(self) = &mrb_struct_type;
st->values = mrb_ary_new_capa(mrb, n);
+ for (i = argc; i < n; i++) {
+ mrb_ary_set(mrb, st->values, i, mrb_nil_value());
+ }
struct_copy(RARRAY_PTR(st->values), argv, argc);
mrb_iv_set(mrb, self, mrb_intern(mrb, "__values__"), st->values);