mbrubeck / mediumvec

Rust collections optimized for size
Apache License 2.0
10 stars 5 forks source link

Handle 16-bit architectures #3

Open mbrubeck opened 7 years ago

mbrubeck commented 7 years ago

Vec32 assumes that casting from u32 to usize is always lossless, which is not true on 8-bit or 16-bit platforms and could cause undefined behavior there.

setharnold commented 7 years ago

How about 'index' larger than 2^31 on 32 bit platforms?

mbrubeck commented 7 years ago

How about 'index' larger than 2^31 on 32 bit platforms?

That would also be bad. Looking closely I don't think it's possible to trigger, because all allocation is done through std::vec::Vec, which panics if it tries to allocate more than isize::MAX bytes. Since cap can never exceed isize::MAX, and len can never exceed cap, the check that index < len is sufficient.