Skip to content

Commit

Permalink
feat(memory): zero initialize upon failed cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Apr 28, 2020
1 parent 62aa7e4 commit 6b4c47d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/mun_memory/src/gc/mark_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ where
unsafe { NonNull::new_unchecked(src) },
unsafe { NonNull::new_unchecked(dest) },
) {
panic!("The Mun Runtime doesn't currently support casting from '{}' to '{}'", old_field.1.name(), new_field.1.name());
// Failed to cast. Use the previously zero-initialized value instead
}
} else {
unsafe {
Expand Down
5 changes: 3 additions & 2 deletions crates/mun_runtime/tests/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ fn map_struct_cast_fields1() {
}

#[test]
#[should_panic]
fn map_struct_cast_fields2() {
let mut driver = TestDriver::new(
r#"
Expand All @@ -291,7 +290,7 @@ fn map_struct_cast_fields2() {
);

let a = -2i16;
let _foo: StructRef = invoke_fn!(driver.runtime_mut(), "foo_new", a).unwrap();
let foo: StructRef = invoke_fn!(driver.runtime_mut(), "foo_new", a).unwrap();

driver.update(
r#"
Expand All @@ -300,6 +299,8 @@ fn map_struct_cast_fields2() {
)
"#,
);

assert_eq!(foo.get::<u16>("0").unwrap(), 0);
}

#[test]
Expand Down

0 comments on commit 6b4c47d

Please sign in to comment.