1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

suppress integer overflow warnings

* util.c: annotate as NO_SANITIZE
* bignum.c: avoid (size_t)--
* marshal.c: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2018-11-15 07:34:01 +00:00
parent a42784000e
commit 86d1fc8863
3 changed files with 15 additions and 9 deletions

View file

@ -418,15 +418,16 @@ bary_small_lshift(BDIGIT *zds, const BDIGIT *xds, size_t n, int shift)
static void
bary_small_rshift(BDIGIT *zds, const BDIGIT *xds, size_t n, int shift, BDIGIT higher_bdigit)
{
size_t i;
BDIGIT_DBL num = 0;
assert(0 <= shift && shift < BITSPERDIG);
num = BIGUP(higher_bdigit);
while (n--) {
BDIGIT x = xds[n];
for (i = 0; i < n; i++) {
BDIGIT x = xds[n - i - 1];
num = (num | x) >> shift;
zds[n] = BIGLO(num);
zds[n - i - 1] = BIGLO(num);
num = BIGUP(x);
}
}
@ -445,8 +446,9 @@ bary_zero_p(const BDIGIT *xds, size_t xn)
static void
bary_neg(BDIGIT *ds, size_t n)
{
while (n--)
ds[n] = BIGLO(~ds[n]);
size_t i;
for (i = 0; i < n; i++)
ds[n - i - 1] = BIGLO(~ds[n - i - 1]);
}
static int
@ -5087,6 +5089,7 @@ rb_big2str(VALUE x, int base)
static unsigned long
big2ulong(VALUE x, const char *type)
{
size_t i;
size_t len = BIGNUM_LEN(x);
unsigned long num;
BDIGIT *ds;
@ -5101,9 +5104,9 @@ big2ulong(VALUE x, const char *type)
num = (unsigned long)ds[0];
#else
num = 0;
while (len--) {
for (i = 0; i < len; i++) {
num <<= BITSPERDIG;
num += (unsigned long)ds[len]; /* overflow is already checked */
num += (unsigned long)ds[len - i - 1]; /* overflow is already checked */
}
#endif
return num;

View file

@ -817,6 +817,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
char sign = BIGNUM_SIGN(obj) ? '+' : '-';
size_t len = BIGNUM_LEN(obj);
size_t slen;
size_t j;
BDIGIT *d = BIGNUM_DIGITS(obj);
slen = SHORTLEN(len);
@ -826,7 +827,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_byte(sign, arg);
w_long((long)slen, arg);
while (len--) {
for (j = 0; j < len; j++) {
#if SIZEOF_BDIGIT > SIZEOF_SHORT
BDIGIT num = *d;
int i;
@ -834,7 +835,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
for (i=0; i<SIZEOF_BDIGIT; i+=SIZEOF_SHORT) {
w_short(num & SHORTMASK, arg);
num = SHORTDN(num);
if (len == 0 && num == 0) break;
if (j == len - 1 && num == 0) break;
}
#else
w_short(*d, arg);

2
util.c
View file

@ -1541,6 +1541,7 @@ cmp(Bigint *a, Bigint *b)
return 0;
}
NO_SANITIZE("unsigned-integer-overflow", static Bigint * diff(Bigint *a, Bigint *b));
static Bigint *
diff(Bigint *a, Bigint *b)
{
@ -2020,6 +2021,7 @@ hexnan(double *rvp, const char **sp)
#endif /*No_Hex_NaN*/
#endif /* INFNAN_CHECK */
NO_SANITIZE("unsigned-integer-overflow", double ruby_strtod(const char *s00, char **se));
double
ruby_strtod(const char *s00, char **se)
{