fn build_script_tables(
    binary: &[u8],
    tables: &[Table],
    script: &mut CompiledScriptMut,
) -> BinaryLoaderResult<()> {
    for table in tables {
        match table.kind {
            TableType::MAIN => {
                let start: usize = table.offset as usize;
                // `check_tables()` ensures that the table indices are in bounds
                assume!(start <= usize::max_value() - (table.count as usize));
                let end: usize = start + table.count as usize;
                let mut cursor = Cursor::new(&binary[start..end]);
                script.type_parameters = load_kinds(&mut cursor)?;
                script.parameters = SignatureIndex::new(read_uleb_u16_internal(&mut cursor)?);
                script.code = load_code_unit(&mut cursor)?;
            }
            TableType::MODULE_HANDLES
            | TableType::STRUCT_HANDLES
            | TableType::FUNCTION_HANDLES
            | TableType::FUNCTION_INST
            | TableType::SIGNATURES
            | TableType::IDENTIFIERS
            | TableType::ADDRESS_IDENTIFIERS
            | TableType::CONSTANT_POOL => {
                continue;
            }
            TableType::STRUCT_DEFS
            | TableType::STRUCT_DEF_INST
            | TableType::FUNCTION_DEFS
            | TableType::FIELD_INST
            | TableType::FIELD_HANDLE
            | TableType::MISC => {
                return Err(VMStatus::new(StatusCode::MALFORMED)
                    .with_message("Bad table in Script".to_string()));
            }
        }
    }
    Ok(())
}
/// Builds tables related to a `CompiledScriptMut`.
Builds tables related to a `CompiledScriptMut`.
Builds tables related to a ` CompiledScriptMut ` .
fn build_script_tables(
    binary: &[u8],
    tables: &[Table],
    script: &mut CompiledScriptMut,
) -> BinaryLoaderResult<()> {
    for table in tables {
        match table.kind {
            TableType::MAIN => {
                let start: usize = table.offset as usize;
                // `check_tables()` ensures that the table indices are in bounds
                assume!(start <= usize::max_value() - (table.count as usize));
                let end: usize = start + table.count as usize;
                let mut cursor = Cursor::new(&binary[start..end]);
                script.type_parameters = load_kinds(&mut cursor)?;
                script.parameters = SignatureIndex::new(read_uleb_u16_internal(&mut cursor)?);
                script.code = load_code_unit(&mut cursor)?;
            }
            TableType::MODULE_HANDLES
            | TableType::STRUCT_HANDLES
            | TableType::FUNCTION_HANDLES
            | TableType::FUNCTION_INST
            | TableType::SIGNATURES
            | TableType::IDENTIFIERS
            | TableType::ADDRESS_IDENTIFIERS
            | TableType::CONSTANT_POOL => {
                continue;
            }
            TableType::STRUCT_DEFS
            | TableType::STRUCT_DEF_INST
            | TableType::FUNCTION_DEFS
            | TableType::FIELD_INST
            | TableType::FIELD_HANDLE
            | TableType::MISC => {
                return Err(VMStatus::new(StatusCode::MALFORMED)
                    .with_message("Bad table in Script".to_string()));
            }
        }
    }
    Ok(())
}
fn build_script_tables ( binary : & [ u8 ] , tables : & [ Table ] , script : & mut CompiledScriptMut , ) -> BinaryLoaderResult < ( ) > { for table in tables { match table . kind { TableType :: MAIN => { let start : usize = table . offset as usize ; // `check_tables()` ensures that the table indices are in bounds assume ! ( start usize max_value ( ) ( table count as usize ) ) ; let end : usize = start + table . count as usize ; let mut cursor = Cursor :: new ( & binary [ start .. end ] ) ; script . type_parameters = load_kinds ( & mut cursor ) ? ; script . parameters = SignatureIndex :: new ( read_uleb_u16_internal ( & mut cursor ) ? ) ; script . code = load_code_unit ( & mut cursor ) ? ; } TableType :: MODULE_HANDLES | TableType :: STRUCT_HANDLES | TableType :: FUNCTION_HANDLES | TableType :: FUNCTION_INST | TableType :: SIGNATURES | TableType :: IDENTIFIERS | TableType :: ADDRESS_IDENTIFIERS | TableType :: CONSTANT_POOL => { continue ; } TableType :: STRUCT_DEFS | TableType :: STRUCT_DEF_INST | TableType :: FUNCTION_DEFS | TableType :: FIELD_INST | TableType :: FIELD_HANDLE | TableType :: MISC => { return Err ( VMStatus :: new ( StatusCode :: MALFORMED ) . with_message ( " " . to_string ( ) ) ) ; } } } Ok ( ( ) ) }
Builds tables related to a `CompiledScriptMut`.
Builds tables related to a ` CompiledScriptMut ` .
binary
&[u8]
tables
&[Table]
script
&mut CompiledScriptMut
binary
&[u8]
tables
&[Table]
script
&mut CompiledScriptMut