Skip to content

Commit

Permalink
Fix error result of clock_time_get (#6812)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo authored Aug 7, 2023
1 parent 4c4663e commit c4eafed
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,20 @@ pub unsafe extern "C" fn clock_time_get(
get_allocation_state(),
AllocationState::StackAllocated | AllocationState::StateAllocated
) {
State::with(|state| {
match id {
CLOCKID_MONOTONIC => {
*time = monotonic_clock::now();
}
CLOCKID_REALTIME => {
let res = wall_clock::now();
*time = Timestamp::from(res.seconds)
.checked_mul(1_000_000_000)
.and_then(|ns| ns.checked_add(res.nanoseconds.into()))
.ok_or(ERRNO_OVERFLOW)?;
}
_ => unreachable!(),
State::with(|state| match id {
CLOCKID_MONOTONIC => {
*time = monotonic_clock::now();
Ok(())
}
Ok(())
CLOCKID_REALTIME => {
let res = wall_clock::now();
*time = Timestamp::from(res.seconds)
.checked_mul(1_000_000_000)
.and_then(|ns| ns.checked_add(res.nanoseconds.into()))
.ok_or(ERRNO_OVERFLOW)?;
Ok(())
}
_ => Err(ERRNO_BADF),
})
} else {
*time = Timestamp::from(0u64);
Expand Down

0 comments on commit c4eafed

Please sign in to comment.