initialize_copy: copy destination object may not be intialized

This commit is contained in:
Yukihiro Matsumoto
2012-05-07 18:02:32 +09:00
parent 9bed29bf96
commit 4f1f243fe7
2 changed files with 5 additions and 2 deletions
+4
View File
@@ -496,6 +496,10 @@ mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy)
if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
}
if (!DATA_PTR(copy)) {
DATA_PTR(copy) = mrb_malloc(mrb, sizeof(struct mrb_time));
DATA_TYPE(copy) = &mrb_time_type;
}
memcpy(DATA_PTR(copy), DATA_PTR(src), sizeof(struct mrb_time));
return copy;
}
+1 -2
View File
@@ -43,7 +43,6 @@ assert("yday") { t1.yday == 71 }
assert("year") { t1.year == 2011 }
t2 = Time.at(7.0e6)
t1.initialize_copy(t2)
assert("initialize_copy") { t1 == t2 }
assert("initialize_copy") { t2.clone == t2 }
report()