summaryrefslogtreecommitdiff
path: root/quickjs.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2024-01-06 11:20:20 +0100
committerFabrice Bellard <fabrice@bellard.org>2024-01-06 11:20:20 +0100
commitbd0b7048de817045a5396fbfee893687521f16de (patch)
treed254d66a438c89c25d29ce06a904af40141ca7ef /quickjs.c
parent3ab1c2b3148d1c70181607002aac23ecdd2ad482 (diff)
downloadquickjs-bd0b7048de817045a5396fbfee893687521f16de.tar.gz
quickjs-bd0b7048de817045a5396fbfee893687521f16de.zip
added a comment for non-initialized warning in Valgrind (github issue #153)
Diffstat (limited to 'quickjs.c')
-rw-r--r--quickjs.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/quickjs.c b/quickjs.c
index 054ac36..ad1cc98 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -7899,6 +7899,16 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
/* fast path for array access */
p = JS_VALUE_GET_OBJ(this_obj);
idx = JS_VALUE_GET_INT(prop);
+ /* Note: this code works even if 'p->u.array.count' is not
+ initialized. There are two cases:
+ - 'p' is an array-like object. 'p->u.array.count' is
+ initialized so the slow_path is taken when the index is
+ out of bounds.
+ - 'p' is not an array-like object. 'p->u.array.count' has
+ any value and potentially not initialized. In all the cases
+ (idx >= len or idx < len) the slow path is taken as
+ expected.
+ */
len = (uint32_t)p->u.array.count;
if (unlikely(idx >= len))
goto slow_path;