Uriopass / Egregoria

3D City Builder without a grid
http://douady.paris/blog/
GNU General Public License v3.0
1.49k stars 51 forks source link

Fix unsoundness in get_mut_pair #39

Closed oberien closed 3 years ago

oberien commented 3 years ago

An unsoundness bug was found in a stackoverflow answer with code similar to the one in the get_mut_pair function. See the SO answer for more information about the problem: https://stackoverflow.com/a/53146512/4159583

shepmaster commented 3 years ago

Many apologies for leading you down the wrong path!

Uriopass commented 3 years ago

I'm sorry I don't think I understand the fix, moving the assert_ne after the get_muts doesn't seem to resolve any soundness issue ? In fact, it looks like it could even be worse ?

Uriopass commented 3 years ago

Ah, I see, the equality test can modify the value ! So you compare the pointers instead. Very smart. Thanks!

Uriopass commented 3 years ago

Actually, I wasn't even using this function. I deleted it :grin: