From b02ef8d513b3ca7f7d21b6d95f8c73b2ca130e2c Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 2 Jan 2023 00:48:57 +0100 Subject: [PATCH] portability: memcpy of size zero is undefined behaviour --- quickjs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index f8b37e497..c1b7db7a2 100644 --- a/quickjs.c +++ b/quickjs.c @@ -32777,8 +32777,10 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) } } else { b->vardefs = (void *)((uint8_t*)b + vardefs_offset); - memcpy(b->vardefs, fd->args, fd->arg_count * sizeof(fd->args[0])); - memcpy(b->vardefs + fd->arg_count, fd->vars, fd->var_count * sizeof(fd->vars[0])); + if (fd->vars && fd->arg_count > 0) { + memcpy(b->vardefs, fd->args, fd->arg_count * sizeof(fd->args[0])); + memcpy(b->vardefs + fd->arg_count, fd->vars, fd->var_count * sizeof(fd->vars[0])); + } } b->var_count = fd->var_count; b->arg_count = fd->arg_count;