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

reference to packed field is unaligned #19

Open
CheetoTrump opened this issue Jun 10, 2023 · 5 comments
Open

reference to packed field is unaligned #19

CheetoTrump opened this issue Jun 10, 2023 · 5 comments

Comments

@CheetoTrump
Copy link

Ive tried
ntapi = "0.4.1"
ntapi = "0.4.0"
ntapi = "0.3.7"

and 32bit and 64bit for each version

I get these errors when compiling the crate

error[E0793]: reference to packed field is unaligned
--> C:\Users\USER.cargo\registry\src\index.crates.io-6f17d22bba15001f\ntapi-0.3.7\src\ntexapi.rs:2783:52
|
2783 | *tick_count.QuadPart_mut() = read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
= note: creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use read_unaligned/write_unaligned (loads and stores via *p must be properly aligned even when using raw pointers)

error[E0793]: reference to packed field is unaligned
--> C:\Users\USER.cargo\registry\src\index.crates.io-6f17d22bba15001f\ntapi-0.3.7\src\ntexapi.rs:2807:25
|
2807 | ((read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad).wrapping_mul((*USER_SHARED_DATA).TickCountMultiplier as u64)) >> 24) as u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
= note: creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use read_unaligned/write_unaligned (loads and stores via *p must be properly aligned even when using raw pointers)

For more information about this error, try rustc --explain E0793.
error: could not compile ntapi (lib) due to 2 previous errors

@eminence
Copy link

This was fixed in the 0.4 release. From the paths in the logs above, you're still using ntapi-0.3.7

@acf-patrick
Copy link

I don't quite get it, why is Cargo/the compiler still using version 0.3.7 of the lib even if one has set explicitly
ntapi = "0.4" in Cargo.toml

@eminence
Copy link

You probably have some other dependency that is requiring 0.3.7 (so both 0.3.7 and 0.4.x are brought into your crate graph).

Try running cargo tree -i ntapi to see all the packages that depend on ntapi

@CheetoTrump
Copy link
Author

i should have sent all 3 errors but i didnt, they were 1:1 but different versions of ntapi

@Gordon01
Copy link

Gordon01 commented Sep 2, 2023

cargo update may help in such cases

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

4 participants