Skip to content

Commit

Permalink
Fix the read implementation on no-std (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau authored Aug 14, 2022
1 parent 4a5d113 commit baab359
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions wasmi_v1/src/module/read.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use core::{fmt, fmt::Display};

#[cfg(not(feature = "std"))]
use core::cmp;

#[cfg(feature = "std")]
use std::io;

Expand Down Expand Up @@ -59,8 +56,8 @@ where
#[cfg(not(feature = "std"))]
impl<'a> Read for &'a [u8] {
fn read(&mut self, buffer: &mut [u8]) -> Result<usize, ReadError> {
let len_copy = cmp::min(self.len(), buffer.len());
buffer.copy_from_slice(&self[..len_copy]);
let len_copy = self.len().min(buffer.len());
buffer[..len_copy].copy_from_slice(&self[..len_copy]);
*self = &self[len_copy..];
Ok(len_copy)
}
Expand Down

0 comments on commit baab359

Please sign in to comment.