Correct invalid type pun
`uint32_t` is not allowed to alias a `float` in C++.
Change-Id: I8ab65ef66f163d8d23a9cc20dba44a3c213f392b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3968579
Auto-Submit: Bruno Pitrus <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Zhenyao Mo <[email protected]>
Commit-Queue: Scott Violet <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1061990}
diff --git a/ui/gfx/half_float.cc b/ui/gfx/half_float.cc
index 8e2f0b2..a1d78d0 100644
--- a/ui/gfx/half_float.cc
+++ b/ui/gfx/half_float.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <cstring>
+
#include "ui/gfx/half_float.h"
namespace gfx {
@@ -9,7 +11,9 @@
void FloatToHalfFloat(const float* input, HalfFloat* output, size_t num) {
for (size_t i = 0; i < num; i++) {
float tmp = input[i] * 1.9259299444e-34f;
- uint32_t tmp2 = *reinterpret_cast<uint32_t*>(&tmp) + (1 << 12);
+ uint32_t tmp2;
+ std::memcpy(&tmp2, &tmp, 4);
+ tmp2 += (1 << 12);
output[i] = (tmp2 & 0x80000000UL) >> 16 | (tmp2 >> 13);
}
}