wasi-c2: completely redo how errors work

This commit is contained in:
Pat Hickey
2021-01-22 15:03:16 -08:00
parent a06c4fbe1a
commit 1d8070b734
8 changed files with 250 additions and 316 deletions

View File

@@ -1,4 +1,4 @@
use crate::Error;
use crate::{Error, ErrorExt};
use wiggle::GuestPtr;
pub struct StringArray {
@@ -59,10 +59,13 @@ impl StringArray {
{
let elem_buffer = buffer
.get_range(cursor..(cursor + len))
.ok_or(Error::Inval)?; // Elements don't fit in buffer provided
.ok_or(Error::invalid_argument())?; // Elements don't fit in buffer provided
elem_buffer.copy_from_slice(bytes)?;
}
buffer.get(cursor + len).ok_or(Error::Inval)?.write(0)?; // 0 terminate
buffer
.get(cursor + len)
.ok_or(Error::invalid_argument())?
.write(0)?; // 0 terminate
head?.write(buffer.get(cursor).expect("already validated"))?;
cursor += len + 1;
}