I would like to remove the alignment of 2 of the [u8] (slice of bytes) to become 1. It is possible to do so by copying the bytes that represent the length by using u16::from_le_bytes.
To use this function we must first transform the pointer of bytes into a slice but we only know that it must be two u8s, so we use the slice::from_raw_parts function to do so. Once we have our slice we need to make it an array of two bytes and give it to u16::from_le_bytes.
The thing is I don’t understand why the conversion between a slice of two bytes into an array of two bytes doesn’t succeed. It really seems to be a bug, maybe even a bug where there is some stack corruption. F*ck it!
Hello,
I would like to remove the alignment of 2 of the
[u8]
(slice of bytes) to become 1. It is possible to do so by copying the bytes that represent the length by usingu16::from_le_bytes
.To use this function we must first transform the pointer of bytes into a slice but we only know that it must be two
u8
s, so we use theslice::from_raw_parts
function to do so. Once we have our slice we need to make it an array of two bytes and give it tou16::from_le_bytes
.The thing is I don’t understand why the conversion between a slice of two bytes into an array of two bytes doesn’t succeed. It really seems to be a bug, maybe even a bug where there is some stack corruption. F*ck it!
This works in the playground but not in the code part I publish in this discussion.