diff options
author | 2019-12-12 10:22:00 -0500 | |
---|---|---|
committer | 2019-12-12 08:33:07 -0800 | |
commit | 17a8ac91e078532e0cbbe15234d84ef2e4543f7c (patch) | |
tree | 32d517f468b2b6e638c637bb18d5fca5385cefea /src | |
parent | a7fc5274ad84987d21c4ead69d4d3772fdcc87d3 (diff) | |
download | bytes-17a8ac91e078532e0cbbe15234d84ef2e4543f7c.tar.gz bytes-17a8ac91e078532e0cbbe15234d84ef2e4543f7c.tar.zst bytes-17a8ac91e078532e0cbbe15234d84ef2e4543f7c.zip |
Fix conversion of empty vectors to Bytes
Closes #340
Diffstat (limited to 'src')
-rw-r--r-- | src/bytes.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/bytes.rs b/src/bytes.rs index f8421ef..08ae3c7 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -709,6 +709,13 @@ impl From<&'static str> for Bytes { impl From<Vec<u8>> for Bytes { fn from(vec: Vec<u8>) -> Bytes { + // into_boxed_slice doesn't return a heap allocation for empty vectors, + // so the pointer isn't aligned enough for the KIND_VEC stashing to + // work. + if vec.is_empty() { + return Bytes::new(); + } + let slice = vec.into_boxed_slice(); let len = slice.len(); let ptr = slice.as_ptr(); |