From d2369a00b94710691e009c30b582b21695e99720 Mon Sep 17 00:00:00 2001 From: Richard Viney Date: Wed, 19 Jun 2024 17:22:07 +1200 Subject: [PATCH] Fix deserialization of sliced bit arrays --- src/ieee_float_js.mjs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ieee_float_js.mjs b/src/ieee_float_js.mjs index c365b2c..ef1f95d 100644 --- a/src/ieee_float_js.mjs +++ b/src/ieee_float_js.mjs @@ -71,12 +71,12 @@ function to_bytes_32(f, littleEndian) { return new BitArray(u8Array); } -function from_bytes_32(f, littleEndian) { - if (f.length !== 4) { +function from_bytes_32(bitArray, littleEndian) { + if (bitArray.length !== 4) { return new Error(Nil); } - const view = new DataView(f.buffer.buffer); + const view = new DataView(bitArray.buffer.buffer, bitArray.buffer.byteOffset); return view.getFloat32(0, littleEndian); } @@ -90,12 +90,12 @@ function to_bytes_64(f, littleEndian) { return new BitArray(u8Array); } -function from_bytes_64(f, littleEndian) { - if (f.length !== 8) { +function from_bytes_64(bitArray, littleEndian) { + if (bitArray.length !== 8) { return new Error(Nil); } - const view = new DataView(f.buffer.buffer); + const view = new DataView(bitArray.buffer.buffer, bitArray.buffer.byteOffset); return view.getFloat64(0, littleEndian); }