You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Points out potential UB when transmuting an integer into a pointer.
As of Rust 1.78, LLVM is informed that this is UB. In <= 1.77 this works, and the change caught me off guard, as an int->ptr conversion happens a lot when dealing with win32.
Advantage
The original code will cause UB if the pointer is dereferenced. The recommended code works as intended.
Drawbacks
Possible false positives, though I'm not sure of the use case.
Example
// win32 tends to hand out isize and wants you to use them as pointerslet l_param:isize = ...;let evt:*mutMSLLHOOKSTRUCT = std::mem::transmute(l_param);
Could be written as:
let l_param:isize = ...;let evt = l_param as*mutMSLLHOOKSTRUCT;
The text was updated successfully, but these errors were encountered:
from the transmute docs: "Transmuting integers to pointers is a largely unspecified operation. It is likely not equivalent to an as cast. Doing non-zero-sized memory accesses with a pointer constructed this way is currently considered undefined behavior."
What it does
Points out potential UB when transmuting an integer into a pointer.
As of Rust 1.78, LLVM is informed that this is UB. In <= 1.77 this works, and the change caught me off guard, as an int->ptr conversion happens a lot when dealing with win32.
Advantage
The original code will cause UB if the pointer is dereferenced. The recommended code works as intended.
Drawbacks
Possible false positives, though I'm not sure of the use case.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: