Work out length of typed array with offset correctly (fix #1204)

This commit is contained in:
Gordon Williams 2017-07-25 08:43:49 +01:00
parent 34f43c4987
commit 101dff8c97
2 changed files with 5 additions and 1 deletions

View File

@ -5,6 +5,7 @@
- Handle out of memory errors in jsvCreateNewChild
- Do not garbage collect inside an IRQ
On nRF52 devices, allow button press at boot to clear out peer manager data
Work out length of typed array with offset correctly (fix #1204)
1v93 : Ensure that specifying too many advertising UUIDs causes an exception, not a reboot
nRF5x: Fix for time jump caused by reentrancy in jshGetSystemTime

View File

@ -337,7 +337,10 @@ JsVar *jswrap_typedarray_constructor(JsVarDataArrayBufferViewType type, JsVar *a
jsExceptionHere(JSET_ERROR, "Unsupported first argument of type %t\n", arr);
return 0;
}
if (length==0) length = (JsVarInt)(jsvGetArrayBufferLength(arrayBuffer) / JSV_ARRAYBUFFER_GET_SIZE(type));
if (length==0) {
length = (JsVarInt)((jsvGetArrayBufferLength(arrayBuffer)-byteOffset) / JSV_ARRAYBUFFER_GET_SIZE(type));
if (length<0) length=0;
}
JsVar *typedArr = jsvNewWithFlags(JSV_ARRAYBUFFER);
if (typedArr) {
typedArr->varData.arraybuffer.type = type;