mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
Assert the LSB is 0 when converting Vec into Bytes
This commit is contained in:
+18
-2
@@ -829,8 +829,17 @@ fn slice_ref_catches_not_an_empty_subset() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn empty_slice_ref_catches_not_an_empty_subset() {
|
||||
let bytes = Bytes::copy_from_slice(&b""[..]);
|
||||
let slice = &b""[0..0];
|
||||
let bytes = Bytes::new();
|
||||
let slice = &b"some other slice"[0..0];
|
||||
|
||||
// Protect this test against Bytes internals.
|
||||
//
|
||||
// This should panic *because* the slice's ptr doesn't fit in the range
|
||||
// of the `bytes`.
|
||||
if bytes.as_ptr() as usize == slice.as_ptr() as usize {
|
||||
// don't panic, failing the test
|
||||
return;
|
||||
}
|
||||
|
||||
bytes.slice_ref(slice);
|
||||
}
|
||||
@@ -865,3 +874,10 @@ fn bytes_reserve_overflow() {
|
||||
|
||||
bytes.reserve(usize::MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes_with_capacity_but_empty() {
|
||||
// See https://github.com/tokio-rs/bytes/issues/340
|
||||
let vec = Vec::with_capacity(1);
|
||||
let _ = Bytes::from(vec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user