Skip to content

Commit

Permalink
Remove redundant casts
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Apr 11, 2024
1 parent de8c8a4 commit 065d05b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions crates/libwasmrun/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->

// Per spec, this should be checked before element segment size.
let array = rt.store.get_array(array_addr);
if dest_offset + size > array.elems.len() as usize {
if dest_offset + size > array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand Down Expand Up @@ -3513,7 +3513,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->

let array = rt.store.get_array_mut(array_addr);

if dest_offset + size > array.elems.len() as usize {
if dest_offset + size > array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand Down Expand Up @@ -3694,7 +3694,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->

let array = rt.store.get_array_mut(array_addr);

if offset + size > array.elems.len() as usize {
if offset + size > array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand Down Expand Up @@ -3733,9 +3733,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->
if src_array_addr == dest_array_addr {
let array = rt.store.get_array_mut(src_array_addr);

if src_offset + size > array.elems.len() as usize
|| dest_offset + size > array.elems.len() as usize
{
if src_offset + size > array.elems.len() || dest_offset + size > array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand All @@ -3747,7 +3745,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->
// checking issues.
let src_array = rt.store.get_array(src_array_addr);

if src_offset + size > src_array.elems.len() as usize {
if src_offset + size > src_array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand All @@ -3756,7 +3754,7 @@ fn exec_instr(rt: &mut Runtime, module_addr: ModuleAddr, instr: Instruction) ->

let dest_array = rt.store.get_array_mut(dest_array_addr);

if dest_offset + size > dest_array.elems.len() as usize {
if dest_offset + size > dest_array.elems.len() {
return Err(ExecError::Trap(Trap::OOBArrayAccess));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/libwasmrun/tests/host_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn host_add(rt: &mut Runtime, _: Option<MemAddr>) -> Result<Vec<Value>> {
Value::I32(a) => a,
_ => panic!(),
};
Ok(vec![Value::I32((arg1 + arg2) as i32)])
Ok(vec![Value::I32(arg1 + arg2)])
}

static TEST_WAST: &str = r#"
Expand Down

0 comments on commit 065d05b

Please sign in to comment.