rust-cv / header-vec

Allows one to store a header struct and a vector all inline in the same memory on the heap and share weak versions for minimizing random lookups in data structures
MIT License
5 stars 2 forks source link

FIX: push() update length after new element got written #9

Closed cehteh closed 1 month ago

cehteh commented 1 month ago

Updating len before the allocation make the last element being uninitialized. When allocation fails and stack unwinds then the Drop will try to drop uninitialized memory at the last element. This would result in UB.

vadixidav commented 1 month ago

I double checked that this doesn't cause any weird behavior in the resizing code. It makes sense since the new element hasn't actually been added until it is written. Good find! Thank you for the contribution.

vadixidav commented 1 month ago

Change is officially live as header-vec version 0.1.3.