The (a+b)/2 or (a+b)>>1 could cause an overflow. Use unsigned bit shift (>>>).
X-SVN-Rev: 30735
/*
******************************************************************************
*
- * Copyright (C) 2009-2010, International Business Machines
+ * Copyright (C) 2009-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
// 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]) {
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 {
/*
*******************************************************************************
-* Copyright (C) 2001-2009, International Business Machines
+* Copyright (C) 2001-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
/* 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) {
/*
*******************************************************************************
- * Copyright (C) 1996-2010, International Business Machines Corporation and *
+ * Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
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);
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];
}