mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
bigint.c (mpz_init_set_int): should avoid integer overflow.
Check MRB_INT_MIN which could overflow by negation.
This commit is contained in:
@@ -66,7 +66,8 @@ mpz_init_set_int(mrb_state *mrb, mpz_t *y, mrb_int v)
|
||||
y->p = (mp_limb*)mrb_malloc(mrb, sizeof(mp_limb)*2);
|
||||
if (v < 0) {
|
||||
y->sn = -1;
|
||||
u = -v;
|
||||
if (v == MRB_INT_MIN) u = v;
|
||||
else u = -v;
|
||||
}
|
||||
else if (v > 0) {
|
||||
y->sn = 1;
|
||||
|
||||
Reference in New Issue
Block a user