From 07fa1cbc4a8938085a716051c0f14a3453a885fb Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 2 Jul 2024 01:43:34 +0300 Subject: [PATCH] Add js_dbuf_realloc to avoid ubsan error --- quickjs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index a61bfe28..fe774fb4 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1388,6 +1388,12 @@ void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size) return rt->mf.js_realloc(&rt->malloc_state, ptr, size); } +static void *js_dbuf_realloc(void *opaque, void *ptr, size_t size) +{ + JSRuntime *rt = opaque; + return js_realloc_rt(rt, ptr, size); +} + size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr) { return rt->mf.js_malloc_usable_size(ptr); @@ -1517,7 +1523,7 @@ static inline int js_resize_array(JSContext *ctx, void **parray, int elem_size, static inline void js_dbuf_init(JSContext *ctx, DynBuf *s) { - dbuf_init2(s, ctx->rt, (DynBufReallocFunc *)js_realloc_rt); + dbuf_init2(s, ctx->rt, js_dbuf_realloc); } static inline int is_digit(int c) {