commit 1ec04bf565f2102639fd4cb7c70e898bc9752c77 parent 58c22010f307cb5e1bbe0a9a34315acd66ced724 Author: Fabrice Bellard <fabrice@bellard.org> Date: Sat, 6 Jan 2024 11:20:20 +0100 added a comment for non-initialized warning in Valgrind (github issue #153) Diffstat:
| M | quickjs/quickjs.c | | | 10 | ++++++++++ |
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c @@ -7914,6 +7914,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;