From 83fa0503121a1363bc3586fe02cb31115b54f06f Mon Sep 17 00:00:00 2001 From: jieke Date: Sat, 12 Oct 2024 12:01:58 +0800 Subject: [PATCH] Improve JS_GetArrayBuffer --- quickjs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/quickjs.c b/quickjs.c index 642ae34..09fb1de 100644 --- a/quickjs.c +++ b/quickjs.c @@ -53214,7 +53214,8 @@ static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj) } /* return NULL if exception. WARNING: any JS call can detach the - buffer and render the returned pointer invalid */ + buffer and render the returned pointer invalid. psize can be + NULL. */ uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj) { JSArrayBuffer *abuf = js_get_array_buffer(ctx, obj); @@ -53224,10 +53225,14 @@ uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj) JS_ThrowTypeErrorDetachedArrayBuffer(ctx); goto fail; } - *psize = abuf->byte_length; + if (psize) { + *psize = abuf->byte_length; + } return abuf->data; fail: - *psize = 0; + if (psize) { + *psize = 0; + } return NULL; }