Use byte conversions over the byte swap functions

base/sys_byteorder.h is going away. Instead, use the byte conversions
in base::numerics to convert from a byte array in big endian to an
integer. This avoids putting big endian data into integer types at all.

mini_chromium was rolled and crashpad updated to work with newer
mac/windows toolchains in order to support C++20 in
f9cee5c147db30dc8fa1a048aabd165965b5cb60.

Bug: 40284755
Change-Id: If690847b7aa54b0216e73ec297eae3d0bca2fa57
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5402184
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
danakj 2024-04-11 12:48:02 -04:00 committed by Crashpad LUCI CQ
parent 8df174c64c
commit 7e0af1d4d4

View File

@ -23,13 +23,15 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string_view>
#include <type_traits>
#include "base/containers/span.h"
#include "base/numerics/byte_conversions.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_byteorder.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_APPLE)
@ -53,11 +55,15 @@ void UUID::InitializeToZero() {
memset(this, 0, sizeof(*this));
}
void UUID::InitializeFromBytes(const uint8_t* bytes) {
memcpy(this, bytes, sizeof(*this));
data_1 = base::NetToHost32(data_1);
data_2 = base::NetToHost16(data_2);
data_3 = base::NetToHost16(data_3);
void UUID::InitializeFromBytes(const uint8_t* bytes_ptr) {
// TODO(crbug.com/40284755): This span construction is unsound. The caller
// should provide a span instead of an unbounded pointer.
base::span<const uint8_t, sizeof(UUID)> bytes(bytes_ptr, sizeof(UUID));
data_1 = base::numerics::U32FromBigEndian(bytes.subspan<0u, 4u>());
data_2 = base::numerics::U16FromBigEndian(bytes.subspan<4u, 2u>());
data_3 = base::numerics::U16FromBigEndian(bytes.subspan<6u, 2u>());
std::ranges::copy(bytes.subspan<8u, 2u>(), data_4);
std::ranges::copy(bytes.subspan<10u, 6u>(), data_5);
}
bool UUID::InitializeFromString(const base::StringPiece& string) {