diff --git a/runtime/builtins/builtins_arraybuffer.cpp b/runtime/builtins/builtins_arraybuffer.cpp index 4c966c09a4f7a2a17f8f02e2b1c30c9fe2be1655..a11d3fda9d042b0bf687b4eddbc27e85c9b35ff8 100644 --- a/runtime/builtins/builtins_arraybuffer.cpp +++ b/runtime/builtins/builtins_arraybuffer.cpp @@ -478,7 +478,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, in // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - unionValue.uValue = *reinterpret_cast(block + byteIndex); + unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) if (std::isnan(unionValue.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) @@ -491,7 +491,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, in // NOLINTNEXTLINE(readability-misleading-indentation) } else if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - unionValue.uValue = *reinterpret_cast(block + byteIndex); + unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) if (std::isnan(unionValue.value) && !JSTaggedValue::IsImpureNaN(unionValue.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) @@ -512,7 +512,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForBigInt(JSThread *thread, { static_assert(std::is_same_v || std::is_same_v, "T must be uint64_t/int64_t"); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto pTmp = *reinterpret_cast(block + byteIndex); + auto pTmp = UnalignedLoad(reinterpret_cast(block + byteIndex)); if (!littleEndian) { pTmp = BSWAP(pTmp); } @@ -534,8 +534,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, in return; } auto int64Val = static_cast(val); - auto *resArr = reinterpret_cast(&int64Val); - res = *resArr; + res = UnalignedLoad(reinterpret_cast(&int64Val)); SetTypeData(block, res, byteIndex); } @@ -568,12 +567,10 @@ void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, auto int64Val = static_cast(val); // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { - auto *pTmp = reinterpret_cast(&int64Val); - int16_t tmp = *pTmp; + auto tmp = UnalignedLoad(reinterpret_cast(&int64Val)); res = static_cast(tmp); } else { // NOLINTNEXTLINE(readability-braces-around-statements) - auto *pTmp = reinterpret_cast(&int64Val); - res = *pTmp; + res = UnalignedLoad(reinterpret_cast(&int64Val)); } if (!littleEndian) { diff --git a/runtime/js_bigint.cpp b/runtime/js_bigint.cpp index 9e035ef26c4228a64b5fdc8c029270a2f3967f07..b4e3897460cf5a2d80ddf6aa2488bb7ce08130de 100644 --- a/runtime/js_bigint.cpp +++ b/runtime/js_bigint.cpp @@ -604,7 +604,7 @@ void BigInt::BigIntToUint64(JSThread *thread, JSHandle bigInt, ui auto len = static_cast(bigUint64->GetLength()); for (int index = len - 1; index >= 0; --index) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *(addr + index) = bigUint64->GetDigit(index); + UnalignedStore(addr + index, bigUint64->GetDigit(index)); } } diff --git a/runtime/js_collator.h b/runtime/js_collator.h index 72c872102711d3a09427a991dfb999f32f786f84..c08fe82914af814ca0fcac5ccb6ce1da742ba8f4 100644 --- a/runtime/js_collator.h +++ b/runtime/js_collator.h @@ -64,7 +64,7 @@ public: return; } auto icuCollator = reinterpret_cast(pointer); - icuCollator->~Collator(); + delete icuCollator; } static void SetIcuCollator(JSThread *thread, const JSHandle &collator, icu::Collator *icuCollator,