From 5df3f8221d48f2007efb9611fed873bac64cacd6 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 29 Jul 2022 10:14:05 +0900 Subject: [PATCH] bigint.c (lzb): check `x==0` before calling clz(). In theory, we should not call lzb() with 0, and we assume checks are done before calling it. But we got a report that we call lzb(0) in some use-case. We could not reproduce the issue, so we add this guard. --- mrbgems/mruby-bigint/core/bigint.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index b7ad5d14f..90fa08417 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -350,6 +350,7 @@ mpz_mul_int(mrb_state *mrb, mpz_t *x, mpz_t *y, mrb_int n) static int lzb(mp_limb x) { + if (x == 0) return 0; #if (defined(__GNUC__) || __has_builtin(__builtin_clz)) if (sizeof(mp_limb) == sizeof(int64_t)) return __builtin_clzll(x);