Skip to content

Commit 638ec8c

Browse files
author
Fabrice Bellard
committed
fixed js_bigint_to_string1() (#412)
1 parent bb986e5 commit 638ec8c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

quickjs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10563,6 +10563,15 @@ static inline js_limb_t js_limb_clz(js_limb_t a)
1056310563
}
1056410564
#endif
1056510565

10566+
/* handle a = 0 too */
10567+
static inline js_limb_t js_limb_safe_clz(js_limb_t a)
10568+
{
10569+
if (a == 0)
10570+
return JS_LIMB_BITS;
10571+
else
10572+
return js_limb_clz(a);
10573+
}
10574+
1056610575
static js_limb_t mp_add(js_limb_t *res, const js_limb_t *op1, const js_limb_t *op2,
1056710576
js_limb_t n, js_limb_t carry)
1056810577
{
@@ -11911,7 +11920,7 @@ static JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, int radix)
1191111920
r = tmp;
1191211921
}
1191311922
log2_radix = 31 - clz32(radix); /* floor(log2(radix)) */
11914-
n_bits = r->len * JS_LIMB_BITS - js_limb_clz(r->tab[r->len - 1]);
11923+
n_bits = r->len * JS_LIMB_BITS - js_limb_safe_clz(r->tab[r->len - 1]);
1191511924
/* n_digits is exact only if radix is a power of
1191611925
two. Otherwise it is >= the exact number of digits */
1191711926
n_digits = (n_bits + log2_radix - 1) / log2_radix;

0 commit comments

Comments
 (0)