ruby-changes:53472
From: shyouhei <ko1@a...>
Date: Tue, 13 Nov 2018 09:40:57 +0900 (JST)
Subject: [ruby-changes:53472] shyouhei:r65688 (trunk): suppress integer overflow warnings
shyouhei 2018-11-13 09:40:52 +0900 (Tue, 13 Nov 2018) New Revision: 65688 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65688 Log: suppress integer overflow warnings * random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h overflows and that seems intentional) * bignum.c: avoid (size_t)-- * cont.c: ditto * util.c: ditto * vm_insnhelper.c: ditto Modified files: trunk/bignum.c trunk/cont.c trunk/random.c trunk/util.c trunk/vm_insnhelper.c Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 65687) +++ vm_insnhelper.c (revision 65688) @@ -3211,7 +3211,7 @@ vm_opt_newarray_max(rb_num_t num, const https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3211 else { struct cmp_opt_data cmp_opt = { 0, 0 }; VALUE result = *ptr; - rb_num_t i = num - 1; + rb_snum_t i = num - 1; while (i-- > 0) { const VALUE v = *++ptr; if (OPTIMIZED_CMP(v, result, cmp_opt) > 0) { @@ -3237,7 +3237,7 @@ vm_opt_newarray_min(rb_num_t num, const https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3237 else { struct cmp_opt_data cmp_opt = { 0, 0 }; VALUE result = *ptr; - rb_num_t i = num - 1; + rb_snum_t i = num - 1; while (i-- > 0) { const VALUE v = *++ptr; if (OPTIMIZED_CMP(v, result, cmp_opt) < 0) { Index: util.c =================================================================== --- util.c (revision 65687) +++ util.c (revision 65688) @@ -54,8 +54,16 @@ ruby_scan_hex(const char *start, size_t https://github.com/ruby/ruby/blob/trunk/util.c#L54 register const char *s = start; register unsigned long retval = 0; const char *tmp; + size_t i = 0; - while (len-- && *s && (tmp = strchr(hexdigit, *s))) { + for (i = 0; i < len; i++) { + if (! s[0]) { + break; + } + tmp = strchr(hexdigit, *s); + if (! tmp) { + break; + } retval <<= 4; retval |= (tmp - hexdigit) & 15; s++; Index: cont.c =================================================================== --- cont.c (revision 65687) +++ cont.c (revision 65688) @@ -1199,7 +1199,7 @@ rollback_ensure_stack(VALUE self,rb_ensu https://github.com/ruby/ruby/blob/trunk/cont.c#L1199 { rb_ensure_list_t *p; rb_ensure_entry_t *entry; - size_t i; + size_t i, j; size_t cur_size; size_t target_size; size_t base_point; @@ -1237,11 +1237,11 @@ rollback_ensure_stack(VALUE self,rb_ensu https://github.com/ruby/ruby/blob/trunk/cont.c#L1237 cur_size--; } /* push ensure stack */ - while (i--) { - func = (VALUE (*)(ANYARGS)) lookup_rollback_func(target[i].e_proc); - if ((VALUE)func != Qundef) { - (*func)(target[i].data2); - } + for (j = 0; j < i; j++) { + func = (VALUE (*)(ANYARGS)) lookup_rollback_func(target[i - j - 1].e_proc); + if ((VALUE)func != Qundef) { + (*func)(target[i - j - 1].data2); + } } } Index: bignum.c =================================================================== --- bignum.c (revision 65687) +++ bignum.c (revision 65688) @@ -2587,10 +2587,9 @@ bigdivrem_single1(BDIGIT *qds, const BDI https://github.com/ruby/ruby/blob/trunk/bignum.c#L2587 size_t i; BDIGIT_DBL t2; t2 = x_higher_bdigit; - i = xn; - while (i--) { - t2 = BIGUP(t2) + xds[i]; - qds[i] = (BDIGIT)(t2 / y); + for (i = 0; i < xn; i++) { + t2 = BIGUP(t2) + xds[xn - i - 1]; + qds[xn - i - 1] = (BDIGIT)(t2 / y); t2 %= y; } return (BDIGIT)t2; Index: random.c =================================================================== --- random.c (revision 65687) +++ random.c (revision 65688) @@ -1573,6 +1573,7 @@ init_seed(struct MT *mt) https://github.com/ruby/ruby/blob/trunk/random.c#L1573 seed.u32[i] = genrand_int32(mt); } +NO_SANITIZE("unsigned-integer-overflow", extern st_index_t rb_hash_start(st_index_t h)); st_index_t rb_hash_start(st_index_t h) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/