From d1ee793b753fa09ebdbe97b6023b3f131d5f741e Mon Sep 17 00:00:00 2001 From: AlexVestin <31164322+AlexVestin@users.noreply.github.com> Date: Wed, 22 Apr 2020 17:25:25 +0200 Subject: [PATCH] Use size of the typed array instead of underlying bufffer If an array is subarrayed from another array they will still have the same underlying buffer giving the wrong size here --- include/addon-tools.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp index fe41eb2..68d9b8c 100644 --- a/include/addon-tools.hpp +++ b/include/addon-tools.hpp @@ -338,7 +338,7 @@ inline Type* getArrayData( size_t offset = ta.ByteOffset(); Napi::ArrayBuffer arr = ta.ArrayBuffer(); if (num) { - *num = arr.ByteLength() / sizeof(Type); + *num = ta.ByteLength() / sizeof(Type); } uint8_t *base = reinterpret_cast(arr.Data()); out = reinterpret_cast(base + offset);