diff --git a/src/stream-reader.hh b/src/stream-reader.hh index 84990d0ee..578366f86 100644 --- a/src/stream-reader.hh +++ b/src/stream-reader.hh @@ -203,8 +203,8 @@ class StreamReader { return false; } - unsigned short val = - *(reinterpret_cast(&binary_[idx_])); + unsigned short val; + memcpy(&val, &binary_[idx_], sizeof(val)); if (swap_endian_) { swap2(&val); @@ -221,7 +221,8 @@ class StreamReader { return false; } - uint32_t val = *(reinterpret_cast(&binary_[idx_])); + uint32_t val; + memcpy(&val, &binary_[idx_], sizeof(val)); if (swap_endian_) { swap4(&val); @@ -238,7 +239,8 @@ class StreamReader { return false; } - int val = *(reinterpret_cast(&binary_[idx_])); + int val; + memcpy(&val, &binary_[idx_], sizeof(val)); if (swap_endian_) { swap4(&val); @@ -255,7 +257,8 @@ class StreamReader { return false; } - uint64_t val = *(reinterpret_cast(&binary_[idx_])); + uint64_t val; + memcpy(&val, &binary_[idx_], sizeof(val)); if (swap_endian_) { swap8(&val); @@ -272,7 +275,8 @@ class StreamReader { return false; } - int64_t val = *(reinterpret_cast(&binary_[idx_])); + int64_t val; + memcpy(&val, &binary_[idx_], sizeof(val)); if (swap_endian_) { swap8(&val); diff --git a/src/tinyusdz.cc b/src/tinyusdz.cc index c34f23fdf..fdc3fd480 100644 --- a/src/tinyusdz.cc +++ b/src/tinyusdz.cc @@ -341,8 +341,8 @@ bool ParseUSDZHeader(const uint8_t *addr, const size_t length, uint16_t compr_method = *reinterpret_cast(&local_header[0] + 8); // uint32_t compr_bytes = *reinterpret_cast(&local_header[0]+18); - uint32_t uncompr_bytes = - *reinterpret_cast(&local_header[0] + 22); + uint32_t uncompr_bytes; + memcpy(&uncompr_bytes, &local_header[22], sizeof(uncompr_bytes)); // USDZ only supports uncompressed ZIP if (compr_method != 0) {