-
Notifications
You must be signed in to change notification settings - Fork 110
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
Unsound construction of uninitialized values #70
Comments
Hey @Ralith! Thanks for calling this out. Based on the documentation, it is not possible to create a struct by calling With that being said though, after the call to |
This is unfortunately false. I did mean it when I said insta-UB. Referring again to the docs:
I haven't fully absorbed the design of this library so I'm not in a good position to recommend new designs. Using raw pointers to construct an intrusive linked list seems reasonable in general, but obtaining a |
Indeed, I should have been more clear and specified that the structs pointed to by
You're correct. While I think in practice the code would be okay because we don't access the uninitialized fields and implement
I actually like this idea and put up a PR taking this approach in #71. Any thoughts or feedback you may have would be welcome. |
Is it still the case? I can't find any dangerous |
A lot of the |
The new approach looks good to me too. |
Great! I'll go ahead and close this issue then. |
https://github.com/jeromefroe/lru-rs/blob/master/src/lib.rs#L222-L223 uses
MaybeUninit
in a way that is exactly equivalent to the oldmem::uninitialized
which was deprecated for being practically always unsound. The correct way to useMaybeUninit
is to never callassume_init
until you have written a legal value to it. In the linked section of code, values of typeK
andV
are obtained from uninitialized memory; these values might have types like&'static [u8]
or!
for which this operation is insta-UB, for example.The text was updated successfully, but these errors were encountered: