diff --git a/cutils.c b/cutils.c index a02fb76..b447e6a 100644 --- a/cutils.c +++ b/cutils.c @@ -140,8 +140,10 @@ int dbuf_put(DynBuf *s, const uint8_t *data, size_t len) if (dbuf_realloc(s, s->size + len)) return -1; } - memcpy(s->buf + s->size, data, len); - s->size += len; + if (len > 0) { + memcpy(s->buf + s->size, data, len); + s->size += len; + } return 0; } diff --git a/libbf.c b/libbf.c index fe1628e..dc00328 100644 --- a/libbf.c +++ b/libbf.c @@ -292,7 +292,8 @@ int bf_set(bf_t *r, const bf_t *a) } r->sign = a->sign; r->expn = a->expn; - memcpy(r->tab, a->tab, a->len * sizeof(limb_t)); + if (a->len > 0) + memcpy(r->tab, a->tab, a->len * sizeof(limb_t)); return 0; } diff --git a/quickjs-libc.c b/quickjs-libc.c index e180dd0..12dc798 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -3462,7 +3462,8 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val, msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len); if (!msg->sab_tab) goto fail; - memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len); + if (sab_tab_len > 0) + memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len); msg->sab_tab_len = sab_tab_len; js_free(ctx, data); diff --git a/quickjs.c b/quickjs.c index 16c6760..b0e91d0 100644 --- a/quickjs.c +++ b/quickjs.c @@ -32595,8 +32595,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->arg_count > 0) + memcpy(b->vardefs, fd->args, fd->arg_count * sizeof(fd->args[0])); + if (fd->var_count > 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;