H-uru / Plasma

Cyan Worlds's Plasma game engine
http://h-uru.github.io/Plasma/
GNU General Public License v3.0
202 stars 80 forks source link

Fix a bad assert in hsRAMStream #1591

Closed dpogue closed 1 month ago

dpogue commented 1 month ago

This was added because UBSan was warning that we were calling memcpy with a null destination, and while that is technically true, it was also a no-op because it was copying 0 bytes. A null buffer gets properly resized with the data in the next step, so this is actually expected behaviour that is broken by asserting too early.

Instead, detect the cases where we're calling memcpy with actual data, and assert in those cases that the RAMStream buffer is non-null.

dpogue commented 1 month ago

I added a (pretty minimal) unit test here that would trigger the previous assert, and is working now with the modified asserts.