fn check_tables(tables: &mut Vec<Table>, end_tables: u64, length: u64) -> BinaryLoaderResult<()> {
    // there is no real reason to pass a mutable reference but we are sorting next line
    tables.sort_by(|t1, t2| t1.offset.cmp(&t2.offset));

    let mut current_offset = end_tables;
    let mut table_types = HashSet::new();
    for table in tables {
        let offset = u64::from(table.offset);
        if offset != current_offset {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        if table.count == 0 {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        let count = u64::from(table.count);
        if let Some(checked_offset) = current_offset.checked_add(count) {
            current_offset = checked_offset;
        }
        if current_offset > length {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        if !table_types.insert(table.kind) {
            return Err(VMStatus::new(StatusCode::DUPLICATE_TABLE));
        }
    }
    if current_offset != length {
        return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
    }
    Ok(())
}
/// Verify correctness of tables.
///
/// Tables cannot have duplicates, must cover the entire blob and must be disjoint.
Verify correctness of tables.
Tables cannot have duplicates, must cover the entire blob and must be disjoint.
Verify correctness of tables . Tables cannot have duplicates must cover the entire blob and must be disjoint .
fn check_tables(tables: &mut Vec<Table>, end_tables: u64, length: u64) -> BinaryLoaderResult<()> {
    // there is no real reason to pass a mutable reference but we are sorting next line
    tables.sort_by(|t1, t2| t1.offset.cmp(&t2.offset));
    let mut current_offset = end_tables;
    let mut table_types = HashSet::new();
    for table in tables {
        let offset = u64::from(table.offset);
        if offset != current_offset {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        if table.count == 0 {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        let count = u64::from(table.count);
        if let Some(checked_offset) = current_offset.checked_add(count) {
            current_offset = checked_offset;
        }
        if current_offset > length {
            return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
        }
        if !table_types.insert(table.kind) {
            return Err(VMStatus::new(StatusCode::DUPLICATE_TABLE));
        }
    }
    if current_offset != length {
        return Err(VMStatus::new(StatusCode::BAD_HEADER_TABLE));
    }
    Ok(())
}
fn check_tables ( tables : & mut Vec < Table > , end_tables : u64 , length : u64 ) -> BinaryLoaderResult < ( ) > { // there is no real reason to pass a mutable reference but we are sorting next line tables . sort_by ( | t1 , t2 | t1 . offset . cmp ( & t2 . offset ) ) ; let mut current_offset = end_tables ; let mut table_types = HashSet :: new ( ) ; for table in tables { let offset = u64 :: from ( table . offset ) ; if offset != current_offset { return Err ( VMStatus :: new ( StatusCode :: BAD_HEADER_TABLE ) ) ; } if table . count == 0 { return Err ( VMStatus :: new ( StatusCode :: BAD_HEADER_TABLE ) ) ; } let count = u64 :: from ( table . count ) ; if let Some ( checked_offset ) = current_offset . checked_add ( count ) { current_offset = checked_offset ; } if current_offset > length { return Err ( VMStatus :: new ( StatusCode :: BAD_HEADER_TABLE ) ) ; } if ! table_types . insert ( table . kind ) { return Err ( VMStatus :: new ( StatusCode :: DUPLICATE_TABLE ) ) ; } } if current_offset != length { return Err ( VMStatus :: new ( StatusCode :: BAD_HEADER_TABLE ) ) ; } Ok ( ( ) ) }
Verify correctness of tables.
Verify correctness of tables .
tables
&mut Vec<Table>
end_tables
u64
length
u64
tables
&mut Vec<Table>
end_tables
u64
length
u64