From 17a8ac91e078532e0cbbe15234d84ef2e4543f7c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 12 Dec 2019 10:22:00 -0500 Subject: [PATCH] Fix conversion of empty vectors to Bytes Closes #340 --- src/bytes.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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> for Bytes { fn from(vec: Vec) -> 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();