Rewrite CompactValue to avoid undefined behavior from the use of a union for type-punning #1154

Closed
htpiv wants to merge 4 commits from htpiv/use-bit-cast into main
Showing only changes of commit 68b780fa37 - Show all commits

View File

@@ -11,6 +11,8 @@
#ifdef __cpp_lib_bit_cast
#include <bit>
#else
#include <cstring>
#endif
rozele commented 2022-07-25 10:01:53 -07:00 (Migrated from github.com)
Review

Looks like internal builds are failing because std::memcpy requires #include <cstring>

Looks like internal builds are failing because std::memcpy requires `#include <cstring>`
#include "YGValue.h"
#include "YGMacros.h"
@@ -169,7 +171,7 @@ private:
static float asFloat(uint32_t u) {
#ifdef __cpp_lib_bit_cast
return std::bit_cast<float>(data);
return std::bit_cast<float>(u);
#else
float f;
static_assert(sizeof(f) == sizeof(u), "uint32_t and float must have the same size");