]> granicus.if.org Git - icu/commitdiff
ICU-8268 computation of average could overflow.
authorAbhinav Gupta <mail@abhinavg.net>
Wed, 28 Sep 2011 20:29:59 +0000 (20:29 +0000)
committerAbhinav Gupta <mail@abhinavg.net>
Wed, 28 Sep 2011 20:29:59 +0000 (20:29 +0000)
The (a+b)/2 or (a+b)>>1 could cause an overflow. Use unsigned bit shift (>>>).

X-SVN-Rev: 30735

icu4j/main/classes/core/src/com/ibm/icu/impl/BMPSet.java
icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java
icu4j/main/classes/core/src/com/ibm/icu/text/BidiLine.java
icu4j/main/classes/core/src/com/ibm/icu/text/BreakCTDictionary.java
icu4j/main/classes/core/src/com/ibm/icu/text/NFRuleSet.java

index 7cb471c9a2a4f78b4acf3a45e531a7636ec99c4d..cbb39eac4446360e06bfaba3131cb814dc435335 100644 (file)
@@ -1,7 +1,7 @@
 /*
  ******************************************************************************
  *
- *   Copyright (C) 2009-2010, International Business Machines
+ *   Copyright (C) 2009-2011, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  ******************************************************************************
@@ -481,7 +481,7 @@ public final class BMPSet {
         // invariant: c >= list[lo]
         // invariant: c < list[hi]
         for (;;) {
-            int i = (lo + hi) >> 1;
+            int i = (lo + hi) >>> 1;
             if (i == lo) {
                 break; // Found!
             } else if (c < list[i]) {
index b230776c35d0f6d6b64276e0979f01d5eff9c582..2341f55dda6d6b0b4389245939ce96aa0f1358b9 100644 (file)
@@ -860,7 +860,7 @@ public final class ICUResourceBundleReader implements ICUBinary.Authenticate {
             start=0;
             limit=size;
             while(start<limit) {
-                mid = (start + limit) / 2;
+                mid = (start + limit) >>> 1;
                 if (keyOffsets != null) {
                     result = reader.compareKeys(key, keyOffsets[mid]);
                 } else {
index 6fd88a9845e43b67b5a9d7b045eaf8d41f7eab66..fdf8cc90f3cc641fb0cbf0218c5fcbac82cba648 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-*   Copyright (C) 2001-2009, International Business Machines
+*   Copyright (C) 2001-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 */
@@ -984,7 +984,7 @@ final class BidiLine {
 
             /* the middle if() is guaranteed to find the run, we don't need a loop limit */
             for ( ; ; ) {
-                i = (begin + limit) / 2;
+                i = (begin + limit) >>> 1;
                 if (visualIndex >= runs[i].limit) {
                     begin = i + 1;
                 } else if (i==0 || visualIndex >= runs[i-1].limit) {
index 2ff5a257639d33b581b5ae3cf868de62d347d8e5..e033881f94980b1cd4239a537b19275b9858d88b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 1996-2010, International Business Machines Corporation and    *
+ * Copyright (C) 1996-2011, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -228,7 +228,7 @@ class BreakCTDictionary {
                 int middle;
                 node = null; // If we don't find a match, we'll fall out of the loop
                 while (high >= low) {
-                    middle = (high + low) / 2;
+                    middle = (high + low) >>> 1;
                     if (uc == hnode[middle].ch) {
                         // We hit a match; get the next node and next character
                         node = getCompactTrieNode(hnode[middle].equal);
index c8ca526e3ee8f425e2f813bb0a65a354a1dd54c6..52b282144a0db6d8277db0e2b64fc3ca15f417f4 100644 (file)
@@ -529,7 +529,7 @@ final class NFRuleSet {
         int hi = rules.length;
     if (hi > 0) {
         while (lo < hi) {
-        int mid = (lo + hi) / 2;
+        int mid = (lo + hi) >>> 1;
         if (rules[mid].getBaseValue() == number) {
             return rules[mid];
         }