From 8f897d64d497eacee884db40a2f86339f6c06c73 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Tue, 2 Jan 2024 16:09:55 +0100 Subject: [PATCH] fixed crash in JS_DumpMemoryUsage (github issue #65) --- quickjs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index bac4aea..d71f0ea 100644 --- a/quickjs.c +++ b/quickjs.c @@ -6279,10 +6279,10 @@ void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) if (obj_classes[0]) fprintf(fp, " %5d %2.0d %s\n", obj_classes[0], 0, "none"); for (class_id = 1; class_id < JS_CLASS_INIT_COUNT; class_id++) { - if (obj_classes[class_id]) { + if (obj_classes[class_id] && class_id < rt->class_count) { char buf[ATOM_GET_STR_BUF_SIZE]; fprintf(fp, " %5d %2.0d %s\n", obj_classes[class_id], class_id, - JS_AtomGetStrRT(rt, buf, sizeof(buf), js_std_class_def[class_id - 1].class_name)); + JS_AtomGetStrRT(rt, buf, sizeof(buf), rt->class_array[class_id].class_name)); } } if (obj_classes[JS_CLASS_INIT_COUNT])