Commit 4f1f243f authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

initialize_copy: copy destination object may not be intialized

parent 9bed29bf
...@@ -496,6 +496,10 @@ mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy) ...@@ -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))) { if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); 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)); memcpy(DATA_PTR(copy), DATA_PTR(src), sizeof(struct mrb_time));
return copy; return copy;
} }
......
...@@ -43,7 +43,6 @@ assert("yday") { t1.yday == 71 } ...@@ -43,7 +43,6 @@ assert("yday") { t1.yday == 71 }
assert("year") { t1.year == 2011 } assert("year") { t1.year == 2011 }
t2 = Time.at(7.0e6) t2 = Time.at(7.0e6)
t1.initialize_copy(t2) assert("initialize_copy") { t2.clone == t2 }
assert("initialize_copy") { t1 == t2 }
report() report()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment