From c83bddd8562be1186347cd0b061c961ab8df8870 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 18 Dec 2024 10:33:58 +0900 Subject: [PATCH] mruby-bigint (bint_new): avoid memcpy'ing NULL pointer The second argument of memcpy() is declared to never be NULL. Clang ASAN report this as an undefined behavior error. --- mrbgems/mruby-bigint/core/bigint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 9a45ae504..8798b696c 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -1263,7 +1263,7 @@ bint_new(mrb_state *mrb, mpz_t *x) if (x->sz <= RBIGINT_EMBED_SIZE_MAX) { RBIGINT_SET_EMBED_SIZE(b, x->sz); RBIGINT_SET_EMBED_SIGN(b, x->sn); - memcpy(RBIGINT_EMBED_ARY(b), x->p, x->sz*sizeof(mp_limb)); + if (x->p) memcpy(RBIGINT_EMBED_ARY(b), x->p, x->sz*sizeof(mp_limb)); mpz_clear(mrb, x); } else {