bfops / playform

Voxel sandbox project in Rust
http://playformdev.blogspot.ca/
MIT License
212 stars 24 forks source link

Undefined use of unsafe #194

Closed bjorn3 closed 6 years ago

bjorn3 commented 6 years ago

https://github.com/bfops/playform/blob/bf71fd54cb21631d9423ab7dc41d46a851b81a09/client/lib/src/view/chunked_terrain.rs#L76-L118

You are first extending the three input vecs with zeros, which is undefined behaviour as zero may not be a valid value for the types. Then you are turn the vecs into raw ptrs and create them again, with a different length, which is not allowed according to the docs. (https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#safety) I suspect this of causing the jemalloc deadlock.

Could you please rewrite it in safe rust.

bfops commented 6 years ago

Thanks, that’s a great catch. I’ll rewrite it and see if jemalloc gets happier.

bfops commented 6 years ago

You are first extending the three input vecs with zeros, which is undefined behaviour as zero may not be a valid value for the types.

Is this true? It's all floats and ints under the surface. Regardless, the alignment and sizing of the types is still making behavior undefined here.

bjorn3 commented 6 years ago

Is this true? It's all floats and ints under the surface.

Nope it isnt true, I should have looked more carefully at the types.

bfops commented 6 years ago

jemalloc works now!

6b5722b062a56c8c5eee1b361b26c11c035c616b d043f8ed30cdda79aaabc7cb635385a8231e33af 0a65cf24b456f0e2d28489c868b57bfd8be8f8bf

Great catch, thanks!