[前][次][番号順一覧][スレッド一覧]

ruby-changes:53523

From: shyouhei <ko1@a...>
Date: Thu, 15 Nov 2018 16:34:07 +0900 (JST)
Subject: [ruby-changes:53523] shyouhei:r65739 (trunk): suppress integer overflow warnings

shyouhei	2018-11-15 16:34:01 +0900 (Thu, 15 Nov 2018)

  New Revision: 65739

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65739

  Log:
    suppress integer overflow warnings
    
    * util.c: annotate as NO_SANITIZE
    * bignum.c: avoid (size_t)--
    * marshal.c: ditto.

  Modified files:
    trunk/bignum.c
    trunk/marshal.c
    trunk/util.c
Index: util.c
===================================================================
--- util.c	(revision 65738)
+++ util.c	(revision 65739)
@@ -1541,6 +1541,7 @@ cmp(Bigint *a, Bigint *b) https://github.com/ruby/ruby/blob/trunk/util.c#L1541
     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) https://github.com/ruby/ruby/blob/trunk/util.c#L2021
 #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)
 {
Index: bignum.c
===================================================================
--- bignum.c	(revision 65738)
+++ bignum.c	(revision 65739)
@@ -418,15 +418,16 @@ bary_small_lshift(BDIGIT *zds, const BDI https://github.com/ruby/ruby/blob/trunk/bignum.c#L418
 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 https://github.com/ruby/ruby/blob/trunk/bignum.c#L446
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5089
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5104
     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;
Index: marshal.c
===================================================================
--- marshal.c	(revision 65738)
+++ marshal.c	(revision 65739)
@@ -817,6 +817,7 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L817
 		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 https://github.com/ruby/ruby/blob/trunk/marshal.c#L827
 
 		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 https://github.com/ruby/ruby/blob/trunk/marshal.c#L835
 		    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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]