aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Steven Fackler <sfackler@palantir.com> 2019-12-12 10:22:00 -0500
committerGravatar Sean McArthur <sean@seanmonstar.com> 2019-12-12 08:33:07 -0800
commit17a8ac91e078532e0cbbe15234d84ef2e4543f7c (patch)
tree32d517f468b2b6e638c637bb18d5fca5385cefea /src
parenta7fc5274ad84987d21c4ead69d4d3772fdcc87d3 (diff)
downloadbytes-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.rs7
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();