Skip to content

Commit 3b45d15

Browse files
committed
Fix endianness handling in js_dataview_getValue / js_dataview_setValue
1 parent 653b227 commit 3b45d15

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

quickjs.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -55157,7 +55157,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
5515755157
{
5515855158
JSTypedArray *ta;
5515955159
JSArrayBuffer *abuf;
55160-
int is_swap, size;
55160+
BOOL littleEndian, is_swap;
55161+
int size;
5516155162
uint8_t *ptr;
5516255163
uint32_t v;
5516355164
uint64_t pos;
@@ -55168,9 +55169,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
5516855169
size = 1 << typed_array_size_log2(class_id);
5516955170
if (JS_ToIndex(ctx, &pos, argv[0]))
5517055171
return JS_EXCEPTION;
55171-
is_swap = TRUE;
55172-
if (argc > 1)
55173-
is_swap = !JS_ToBool(ctx, argv[1]);
55172+
littleEndian = argc > 1 && JS_ToBool(ctx, argv[1]);
55173+
is_swap = littleEndian ^ !is_be();
5517455174
abuf = ta->buffer->u.array_buffer;
5517555175
if (abuf->detached)
5517655176
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
@@ -55255,7 +55255,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
5525555255
{
5525655256
JSTypedArray *ta;
5525755257
JSArrayBuffer *abuf;
55258-
int is_swap, size;
55258+
BOOL littleEndian, is_swap;
55259+
int size;
5525955260
uint8_t *ptr;
5526055261
uint64_t v64;
5526155262
uint32_t v;
@@ -55294,9 +55295,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
5529455295
v64 = u.u64;
5529555296
}
5529655297
}
55297-
is_swap = TRUE;
55298-
if (argc > 2)
55299-
is_swap = !JS_ToBool(ctx, argv[2]);
55298+
littleEndian = argc > 2 && JS_ToBool(ctx, argv[2]);
55299+
is_swap = littleEndian ^ !is_be();
5530055300
abuf = ta->buffer->u.array_buffer;
5530155301
if (abuf->detached)
5530255302
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);

0 commit comments

Comments
 (0)