1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:57:44 +00:00

LibCrypto+LibTLS: Avoid unaligned reads and writes

This adds an `AK::ByteReader` to help with that so we don't duplicate
the logic all over the place.
No more `*(const u16*)` and `*(const u32*)` for anyone.
This should help a little with #7060.
This commit is contained in:
Ali Mohammad Pur 2021-05-14 09:22:56 +04:30 committed by Linus Groh
parent bfd4c7a16c
commit df515e1d85
6 changed files with 88 additions and 17 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteReader.h>
#include <AK/Debug.h>
#include <AK/MemoryStream.h>
#include <AK/Types.h>
@ -15,14 +16,13 @@ namespace {
static u32 to_u32(const u8* b)
{
return AK::convert_between_host_and_big_endian(*(const u32*)b);
return AK::convert_between_host_and_big_endian(ByteReader::load32(b));
}
static void to_u8s(u8* b, const u32* w)
{
for (auto i = 0; i < 4; ++i) {
auto& e = *((u32*)(b + i * 4));
e = AK::convert_between_host_and_big_endian(w[i]);
ByteReader::store(b + i * 4, AK::convert_between_host_and_big_endian(w[i]));
}
}