Validate descriptor max on creating new table or memory (#186)

This commit is contained in:
Mackenzie Clark
2019-02-15 13:14:42 -08:00
committed by GitHub
parent b68b109b7d
commit 2d2d708500
3 changed files with 23 additions and 0 deletions

View File

@ -63,6 +63,15 @@ impl Memory {
/// # }
/// ```
pub fn new(desc: MemoryDescriptor) -> Result<Self, CreationError> {
if let Some(max) = desc.maximum {
if max < desc.minimum {
return Err(CreationError::InvalidDescriptor(
"Max number of memory pages is less than the minimum number of pages"
.to_string(),
));
}
}
let variant = if !desc.shared {
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
} else {