aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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();