mruby-bigint (udiv): narrow the scope of loop variable 'i'

This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-01-02 15:22:45 +09:00
parent d944a079a3
commit d632085b5b
+3 -2
View File
@@ -478,7 +478,6 @@ udiv(mrb_state *mrb, mpz_t *qq, mpz_t *rr, mpz_t *xx, mpz_t *yy)
}
mpz_t q, x, y;
size_t i;
mrb_assert(!uzero(yy)); /* divided by zero */
mpz_init(mrb, &q);
@@ -502,6 +501,8 @@ udiv(mrb_state *mrb, mpz_t *qq, mpz_t *rr, mpz_t *xx, mpz_t *yy)
else
qhat = (((mp_dbl_limb)x.p[j+yd] << DIG_SIZE) + x.p[j+yd-1]) / z;
if (qhat) {
size_t i;
for (i=0; i<yd; i++) {
mp_dbl_limb zz = qhat * y.p[i];
mp_dbl_limb_signed u = LOW(b)+x.p[i+j]-LOW(zz);
@@ -512,7 +513,7 @@ udiv(mrb_state *mrb, mpz_t *qq, mpz_t *rr, mpz_t *xx, mpz_t *yy)
}
for (; b!=0; qhat--) {
mp_dbl_limb c = 0;
for (i=0; i<yd; i++) {
for (size_t i=0; i<yd; i++) {
c += (mp_dbl_limb)x.p[i+j] + (mp_dbl_limb)y.p[i];
x.p[i+j] = LOW(c);
c = HIGH(c);