Hacker News new | past | comments | ask | show | jobs | submit login

> However, if the type is Copy and all the bytes are zeros, then you know it can be calloc

That's not as easy to check as one would think since Copy types can still contain uninitialized bytes.




Yeah, but in the common case all the uninitialized bytes are in the padding at the end of the struct (since Rust can re-arrange fields).

Especially in a case like in the article, where the type is very small (one byte), and the obstacle is that the author is using a newtype.


Knowing that they usually are at the end doesn't help since you still need to write a general runtime check that expresses "are all the bits for this type zero or uninit". Afaik currently there is no way to do this without causing UB. This would need some new intrinsic.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: