diff --git a/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp b/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp index 7175e1896e9e26c85c824c1f1fe5d29c00f16bcb..785b76912eec01664244db988d294e5fe3321261 100644 --- a/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "libpandabase/mem/mem.h" +#include "plugins/ets/runtime/types/ets_primitives.h" #include "plugins/ets/runtime/types/ets_typed_arrays.h" #include "plugins/ets/runtime/types/ets_typed_unsigned_arrays.h" #include "intrinsics.h" @@ -47,13 +49,15 @@ static void EtsEscompatTypedArraySet(T *thisArray, EtsInt pos, typename T::Eleme return; } + // Boundary Check if (UNLIKELY(pos < 0 || pos >= thisArray->GetLengthInt())) { EtsCoroutine *coro = EtsCoroutine::GetCurrent(); ThrowEtsException(coro, panda_file_items::class_descriptors::RANGE_ERROR, "invalid index"); return; } - ObjectAccessor::SetPrimitive( - data, pos * sizeof(typename T::ElementType) + static_cast(thisArray->GetByteOffset()), val); + + auto *dataPtr = ToVoidPtr(ToUintPtr(data) + static_cast(thisArray->GetByteOffset())); + reinterpret_cast(dataPtr)[pos] = val; } template @@ -64,13 +68,15 @@ typename T::ElementType EtsEscompatTypedArrayGet(T *thisArray, EtsInt pos) return 0; } + // Boundary Check if (UNLIKELY(pos < 0 || pos >= thisArray->GetLengthInt())) { EtsCoroutine *coro = EtsCoroutine::GetCurrent(); ThrowEtsException(coro, panda_file_items::class_descriptors::RANGE_ERROR, "invalid index"); return 0; } - return ObjectAccessor::GetPrimitive( - data, pos * sizeof(typename T::ElementType) + static_cast(thisArray->GetByteOffset())); + + auto *dataPtr = ToVoidPtr(ToUintPtr(data) + static_cast(thisArray->GetByteOffset())); + return reinterpret_cast(dataPtr)[pos]; } extern "C" void EtsEscompatInt8ArraySetInt(ark::ets::EtsEscompatInt8Array *thisArray, EtsInt pos, EtsInt val)