#1 Unrestrict the memory alignment of the Representable of an [u8]

Opened by Kerollmops on Feb 14, 2021, 12:06 PM
// Kerollmops on Feb 14, 2021, 12:06 PM

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 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!

This works in the playground but not in the code part I publish in this discussion.

Kerollmops
~ Kerollmops authored a change · pushed by Kerollmops on Feb 14, 2021, 12:09 PM
· on Feb 14, 2021, 12:06 PM
  • sanakirja-core/src/lib.rs
  • "sanakirja/src/tests.rs"
  • sanakirja/src/tests.rs
  • sanakirja/Cargo.toml
not in any channel
GTBDZYZZP6TRTCC5OYDGKZN6AKJEKCK6Y6BJYPRG5Q7SQJ7M7ZEQC
// fogti on Feb 16, 2021, 7:29 PM

In the attached change, there is an unrelated change section which adds a dependency on uuid, which probably shouldn’t be part of the change.