]> granicus.if.org Git - icu/commitdiff
ICU-8854 bitwise and/or of signed byte value.
authorAbhinav Gupta <mail@abhinavg.net>
Mon, 24 Oct 2011 19:24:08 +0000 (19:24 +0000)
committerAbhinav Gupta <mail@abhinavg.net>
Mon, 24 Oct 2011 19:24:08 +0000 (19:24 +0000)
Values loaded from a byte array are sign extended to 32-bits before any
bitwise operations are performed. Should &-down back to one-byte.

X-SVN-Rev: 30862

icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetISCII.java
icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetMBCS.java
icu4j/main/classes/collate/src/com/ibm/icu/text/CollationKey.java

index b33e4025e4d484d6fc9de21d555f98d8add5782d..531ccdaf53fd9321e3f5f4d3961cdf9c8802f9a5 100644 (file)
@@ -1234,7 +1234,7 @@ class CharsetISCII extends CharsetICU {
                 /* Write the language code following LF only if LF is not the last character. */
                 if (fromUnicodeStatus == LF) {
                     targetByteUnit = ATR << 8;
-                    targetByteUnit += (byte)lookupInitialData[range].isciiLang;
+                    targetByteUnit += 0xff & (byte)lookupInitialData[range].isciiLang;
                     fromUnicodeStatus = 0x0000;
                     /* now append ATR and language code */
                     cr = WriteToTargetFromU(offsets, source, target, targetByteUnit);
index 0d384369dfddcb9637e63173c38b598d139c0aa7..9a1ec64a54856a06f7d0fb6d495a7b6b348099a3 100644 (file)
@@ -623,7 +623,7 @@ class CharsetMBCS extends CharsetICU {
             int st1, st2, st3, i;
             
             for (st1 = 0; stageUTF8Index < stageUTF8Length; ++st1) {
-                st2 = ((char)stage[2*st1]<<8) | stage[2*st1+1];
+                st2 = ((char)stage[2*st1]<<8) | (0xff & stage[2*st1+1]);
                 if (st2 != stage1Length/2) {
                     /* each stage 2 block has 64 entries corresponding to 16 entries in the mbcsIndex */
                     for (i = 0; i < 16; ++i) {
index fddd61cb0a17494fa16e27e4bf3fd13377f16669..ab747a1ad5072bb90d80a44c67343e71dc38100f 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.                                                *
 *******************************************************************************
 */
@@ -345,7 +345,7 @@ public final class CollationKey implements Comparable<CollationKey>
                 StringBuilder key = new StringBuilder(size);
                 int i = 0;
                 while (m_key_[i] != 0 && m_key_[i + 1] != 0) {
-                    key.append((char)((m_key_[i] << 8) | m_key_[i + 1]));
+                    key.append((char)((m_key_[i] << 8) | (0xff & m_key_[i + 1])));
                     i += 2;
                 }
                 if (m_key_[i] != 0) {