Possible undefined behavior: dangling reference exists
Closed this issue · 0 comments
statiolake commented
proconio-rs/proconio/src/source/line.rs
Lines 53 to 54 in 1e72f67
The first line drops the original string contained in current_context
so at this moment tokens
is referring to the freed memory. The existence of the dangling reference is considered to be an undefined behavior, this code should be fixed. Store the string in a local variable, assign the refeference first, then assign the context.
Also we can probably use Box::leak()
to get &’static str
and can remove transmute()
s.