ICU-8268 computation of average could overflow.

The (a+b)/2 or (a+b)>>1 could cause an overflow. Use unsigned bit shift (>>>).

X-SVN-Rev: 30735
This commit is contained in:
Abhinav Gupta 2011-09-28 20:29:59 +00:00
parent 24f423c0f8
commit 6916271396
5 changed files with 8 additions and 8 deletions

View 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. * Corporation and others. All Rights Reserved.
* *
****************************************************************************** ******************************************************************************
@ -481,7 +481,7 @@ public final class BMPSet {
// invariant: c >= list[lo] // invariant: c >= list[lo]
// invariant: c < list[hi] // invariant: c < list[hi]
for (;;) { for (;;) {
int i = (lo + hi) >> 1; int i = (lo + hi) >>> 1;
if (i == lo) { if (i == lo) {
break; // Found! break; // Found!
} else if (c < list[i]) { } else if (c < list[i]) {

View File

@ -860,7 +860,7 @@ public final class ICUResourceBundleReader implements ICUBinary.Authenticate {
start=0; start=0;
limit=size; limit=size;
while(start<limit) { while(start<limit) {
mid = (start + limit) / 2; mid = (start + limit) >>> 1;
if (keyOffsets != null) { if (keyOffsets != null) {
result = reader.compareKeys(key, keyOffsets[mid]); result = reader.compareKeys(key, keyOffsets[mid]);
} else { } else {

View 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. * 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 */ /* the middle if() is guaranteed to find the run, we don't need a loop limit */
for ( ; ; ) { for ( ; ; ) {
i = (begin + limit) / 2; i = (begin + limit) >>> 1;
if (visualIndex >= runs[i].limit) { if (visualIndex >= runs[i].limit) {
begin = i + 1; begin = i + 1;
} else if (i==0 || visualIndex >= runs[i-1].limit) { } else if (i==0 || visualIndex >= runs[i-1].limit) {

View 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. * * others. All Rights Reserved. *
******************************************************************************* *******************************************************************************
*/ */
@ -228,7 +228,7 @@ class BreakCTDictionary {
int middle; int middle;
node = null; // If we don't find a match, we'll fall out of the loop node = null; // If we don't find a match, we'll fall out of the loop
while (high >= low) { while (high >= low) {
middle = (high + low) / 2; middle = (high + low) >>> 1;
if (uc == hnode[middle].ch) { if (uc == hnode[middle].ch) {
// We hit a match; get the next node and next character // We hit a match; get the next node and next character
node = getCompactTrieNode(hnode[middle].equal); node = getCompactTrieNode(hnode[middle].equal);

View File

@ -529,7 +529,7 @@ final class NFRuleSet {
int hi = rules.length; int hi = rules.length;
if (hi > 0) { if (hi > 0) {
while (lo < hi) { while (lo < hi) {
int mid = (lo + hi) / 2; int mid = (lo + hi) >>> 1;
if (rules[mid].getBaseValue() == number) { if (rules[mid].getBaseValue() == number) {
return rules[mid]; return rules[mid];
} }