BurntSushi / byteorder

Rust library for reading/writing numbers in big-endian and little-endian.
The Unlicense
984 stars 144 forks source link

write_int never panics on out of range input #205

Open fintelia opened 8 months ago

fintelia commented 8 months ago

The documentation for ByteOrder::write_int says:

If n is not representable in nbytes, or if nbytes is > 8, then this method panics.

However, passing inputs that fail the first condition doesn't actually cause a panic:

BigEndian::write_int(&mut [0; 8], 99999999, 1); // Doesn't panic
BigEndian::write_int(&mut [0; 8], -99999999, 1); // Also doesn't panic