mruby-bigint (mpz_init_set_str): should skip + in the string

When the string starts with `+` it should not cause error silently. It
might cause serious error afterwards.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-10-22 14:35:10 +09:00
parent f2908031c4
commit 11cff8fa7d
+4 -1
View File
@@ -730,6 +730,9 @@ mpz_init_set_str(mrb_state *mrb, mpz_t *x, const char *s, mrb_int len, mrb_int b
if (*s == '-') {
sn = -1; s++;
}
else if (*s == '+') {
sn = 1; s++;
}
else
sn = 1;
for (mrb_int i=0; i<len; i++) {
@@ -751,7 +754,7 @@ mpz_init_set_str(mrb_state *mrb, mpz_t *x, const char *s, mrb_int len, mrb_int b
mpz_mul_int(mrb, x, base);
mpz_add_int(mrb, x, k);
}
x->sn = sn;
x->sn = x->sz == 0 ? 0 : sn;
return retval;
}