Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UB on aarch64_be-unknown-linux-gnu_ilp32 #474

Closed
Noratrieb opened this issue Oct 18, 2023 · 1 comment
Closed

UB on aarch64_be-unknown-linux-gnu_ilp32 #474

Noratrieb opened this issue Oct 18, 2023 · 1 comment

Comments

@Noratrieb
Copy link
Member

use std::collections::HashMap;

fn main() {
    let mut map = HashMap::new();
    map.insert(1, "a");
    
    println!("map = {:?}", map);
}
error: Undefined Behavior: out-of-bounds pointer arithmetic: alloc1009 has size 60, so pointer to 12 bytes starting at offset -12 is out-of-bounds
   --> /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.0/src/raw/mod.rs:510:22
    |
510 |             unsafe { self.ptr.as_ptr().sub(1) }
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: alloc1009 has size 60, so pointer to 12 bytes starting at offset -12 is out-of-bounds
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc1009 was allocated here:
   --> src/main.rs:5:5
    |
5   |     map.insert(1, "a");
    |     ^^^^^^^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
    = note: inside `hashbrown::raw::Bucket::<(i32, &str)>::as_ptr` at /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.0/src/raw/mod.rs:510:22: 510:46
    = note: inside `hashbrown::raw::Bucket::<(i32, &str)>::as_ref::<'_>` at /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.0/src/raw/mod.rs:674:11: 674:24
    = note: inside `<hashbrown::map::Iter<'_, i32, &str> as std::iter::Iterator>::next` at /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.0/src/map.rs:4737:25: 4737:35
    = note: inside `<std::collections::hash_map::Iter<'_, i32, &str> as std::iter::Iterator>::next` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs:2232:9: 2232:25
    = note: inside `std::fmt::DebugMap::<'_, '_>::entries::<&i32, &&str, std::collections::hash_map::Iter<'_, i32, &str>>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:893:23: 893:30
    = note: inside `<std::collections::HashMap<i32, &str> as std::fmt::Debug>::fmt` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs:1309:9: 1309:43

rust-lang/rust#116880

@Amanieu
Copy link
Member

Amanieu commented Oct 18, 2023

Fixed by #475.

@Amanieu Amanieu closed this as completed Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants