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
The general pattern of the code this should complain about is something like
let x = &(some expression that is stored in a temporary variable on the stack)as*constT;
Similar with using addr_of! instead of & and casts, etc.
Concrete examples this would catch are
let x = &(1 + 2)as*consti32;let x = &(x as*consti32)as*const*consti32;
In both cases the part in the parenthesis is stored in a temporary stack location that is no longer valid after the whole statement.
It should however not catch
let x = &(*ptr).xas*constT;let x = &(some_variable)as*constT;
Advantage
Whatever pointer is created there is pointing to no longer valid stack memory, so any usage afterwards will be unsound
Drawbacks
Theoretically this could cause false positives but the only case I can see where the resulting code is not unsound is if you cast the pointer to an usize and do some calculations with it. I don't see how that could lead to any useful results in such a context though.