bignum.c: BDIGIT might or might not integer-promote

BDIGIT can be unsigned int or unsigned short, depending on BDIGIT_DBL.
Given that, unsigned int and unsigned short are different in how
integer promotion works.  BOGLO assumes its argument is wider than
BDIGIT, which is not always true.  We have to force that explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2018-11-16 02:59:30 +00:00
Родитель 6732423b5e
Коммит ca14914039
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -1445,7 +1445,9 @@ bary_add_one(BDIGIT *ds, size_t n)
{
size_t i;
for (i = 0; i < n; i++) {
ds[i] = BIGLO(ds[i]+1);
BDIGIT_DBL n = ds[i];
n += 1;
ds[i] = BIGLO(n);
if (ds[i] != 0)
return 0;
}
@ -5271,8 +5273,12 @@ big2dbl(VALUE x)
}
}
if (carry) {
dl &= BDIGMAX << bits;
dl = BIGLO(dl + ((BDIGIT)1 << bits));
BDIGIT mask = BDIGMAX;
BDIGIT bit = 1;
mask <<= bits;
bit <<= bits;
dl &= mask;
dl |= bit;
if (!dl) d += 1;
}
}