rust-objc icon indicating copy to clipboard operation
rust-objc copied to clipboard

Unsound drop of uninitialised variable in Object::set_ivar.

Open quadrupleslap opened this issue 7 years ago • 2 comments
trafficstars

There needs to be a way to initialize values, probably just calling ptr::write.

quadrupleslap avatar Jan 30 '18 18:01 quadrupleslap

I never considered that someone might keep types that implement Drop in ivars! @quadrupleslap can you tell me more about your use case? I'm not sure how you'd plan to drop them (implement dealloc?) and what new APIs that would require.

The easy way to fix the unsoundness would be just adding a : Copy bound, but if you want to store Drop types that still doesn't help you 😛

SSheldon avatar Feb 04 '18 19:02 SSheldon

I was trying to set some boxed values, but it's fine - it's not essential. Adding a Copy requirement sounds like a good idea, but I'm not sure if it's better than just adding Object::init_ivar, and adding a notice to the other *_ivar methods that the value might be uninitialized and that the user should call init_ivar first. The problem with that is that it doesn't automatically free the values, which is technically sound, but not very nice.

quadrupleslap avatar Feb 05 '18 00:02 quadrupleslap