From a194b68daf5b9beceecf5087df66ccf1873d349b Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 7 Oct 2024 22:07:26 +0200 Subject: [PATCH 1/5] Improve gcc warning fix --- CMakeLists.txt | 1 - quickjs.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aabaf5a69..5af3fef6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ xcheck_add_c_compiler_flag(-Wno-unused-parameter) xcheck_add_c_compiler_flag(-Wno-unused-but-set-variable) xcheck_add_c_compiler_flag(-Wno-array-bounds) xcheck_add_c_compiler_flag(-Wno-format-truncation) -xcheck_add_c_compiler_flag(-Wno-format-zero-length) xcheck_add_c_compiler_flag(-funsigned-char) # ClangCL is command line compatible with MSVC, so 'MSVC' is set. diff --git a/quickjs.c b/quickjs.c index bdc0cc885..38a0fdce7 100644 --- a/quickjs.c +++ b/quickjs.c @@ -34643,7 +34643,7 @@ static JSString *JS_ReadString(BCReaderState *s) } #ifdef DUMP_READ_OBJECT if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) { - bc_read_trace(s, ""); // hex dump and indentation + bc_read_trace(s, "%s", ""); // hex dump and indentation JS_DumpString(s->ctx->rt, p); printf("\n"); } @@ -34703,7 +34703,7 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b, const uint8_t *save_ptr = s->ptr; s->ptr = s->ptr_last + len; s->level -= 4; - bc_read_trace(s, ""); // hex dump + indent + bc_read_trace(s, "%s", ""); // hex dump + indent dump_single_byte_code(s->ctx, bc_buf + pos, b, s->ptr - s->buf_start - len); s->level += 4; From bc784664972718eb79446a54ff67e606605feb67 Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 7 Oct 2024 22:08:00 +0200 Subject: [PATCH 2/5] Follow declaration of variables before for loop --- quickjs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/quickjs.c b/quickjs.c index 38a0fdce7..9b1969daf 100644 --- a/quickjs.c +++ b/quickjs.c @@ -6673,7 +6673,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, } done: if (has_prepare) { - int j = 0; + int j = 0, k; stack = JS_NewArray(ctx); if (JS_IsException(stack)) { stack = JS_NULL; @@ -6689,7 +6689,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, } } // Clear the csd's we didn't use in case of error. - for (int k = j; k < i; k++) { + for (k = j; k < i; k++) { JS_FreeValue(ctx, csd[k].filename); JS_FreeValue(ctx, csd[k].func); JS_FreeValue(ctx, csd[k].func_name); @@ -49847,7 +49847,9 @@ static struct { }; static BOOL string_get_tzabbr(const uint8_t *sp, int *pp, int *offset) { - for (size_t i = 0; i < countof(js_tzabbr); i++) { + size_t i; + + for (i = 0; i < countof(js_tzabbr); i++) { if (string_match(sp, pp, js_tzabbr[i].name)) { *offset = js_tzabbr[i].offset; return TRUE; From ed84f5a85f713fd887c1dc7c8c59cbfc2b87f625 Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 7 Oct 2024 22:08:31 +0200 Subject: [PATCH 3/5] Don't include pthread on wasi or enscripten --- cutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cutils.h b/cutils.h index 76cb460bd..7830d0aeb 100644 --- a/cutils.h +++ b/cutils.h @@ -49,7 +49,7 @@ extern "C" { #elif defined(_WIN32) #include #endif -#if !defined(_WIN32) +#if !defined(_WIN32) && !defined(EMSCRIPTEN) && !defined(__wasi__) #include #include #endif From 5c476a0c35a7663c7d75f571835b4eebf7fa4bb6 Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 7 Oct 2024 22:09:06 +0200 Subject: [PATCH 4/5] Fix out-of-bound write in libbf --- libbf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libbf.c b/libbf.c index 5d48db622..6293f4ea1 100644 --- a/libbf.c +++ b/libbf.c @@ -1710,6 +1710,13 @@ static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, slimb_t d; na = n + nb; + +#if LIMB_LOG2_BITS == 6 + if (na >= (SIZE_MAX / sizeof(limb_t)) - 1) { + return BF_ST_MEM_ERROR; /* Return memory error status */ + } +#endif + taba = bf_malloc(s, (na + 1) * sizeof(limb_t)); if (!taba) goto fail; From 1f56f34d71f0f103b1948c481ebc8c5b12c79f87 Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 7 Oct 2024 22:09:21 +0200 Subject: [PATCH 5/5] Fix MSVC compilation when atomics experimental feature is not set --- quickjs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index 9b1969daf..a8a742477 100644 --- a/quickjs.c +++ b/quickjs.c @@ -62,7 +62,7 @@ #define NO_TM_GMTOFF #endif -#if !defined(EMSCRIPTEN) && !defined(__wasi__) +#if !defined(EMSCRIPTEN) && !defined(__wasi__) && !defined(__STDC_NO_ATOMICS__) #include "quickjs-c-atomics.h" #define CONFIG_ATOMICS #endif