]> granicus.if.org Git - icu/commitdiff
ICU-9205 Update max bytes per char calculation for EBCDIC DBCS types
authorMichael Ow <mow@svn.icu-project.org>
Tue, 3 Apr 2012 22:18:45 +0000 (22:18 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Tue, 3 Apr 2012 22:18:45 +0000 (22:18 +0000)
X-SVN-Rev: 31675

icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetMBCS.java
icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestCharset.java

index 12d816eac4eb731f965064ec1fcd82ddce40899a..24e1378c483bbb2335dc56bf258988bd074de1c3 100644 (file)
@@ -1,6 +1,6 @@
 /**
  *******************************************************************************
- * Copyright (C) 2006-2011, International Business Machines Corporation and    *
+ * Copyright (C) 2006-2012, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  *
@@ -913,7 +913,8 @@ class CharsetMBCS extends CharsetICU {
 
         /* fix maxBytesPerUChar depending on outputType and options etc. */
         if (outputType == MBCS_OUTPUT_2_SISO) {
-            maxBytesPerChar = 3; /* SO+DBCS */
+            /* changed from 3 to 4 in ICU4J only. #9205 */
+            maxBytesPerChar = 4; /* SO+DBCS+SI*/
         }
 
         extIndexes = mbcsTable.extIndexes;
index b6ac4bb353a5505a17b90419860e3295129b9b8e..995dc32e517925aed424e8123fce5a6a25a82c2d 100644 (file)
@@ -1,6 +1,6 @@
 /**
 *******************************************************************************
-* Copyright (C) 2006-2011, International Business Machines Corporation and    *
+* Copyright (C) 2006-2012, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 *
@@ -5656,7 +5656,7 @@ public class TestCharset extends TestFmwk {
         int[] expected = {
                 40,
                 20,
-                60,
+                80, /* changed from 60 to 80 to reflect the updates by #9205 */
                 80,
                 60
         };
@@ -5717,4 +5717,22 @@ public class TestCharset extends TestFmwk {
             }
         }
     }
+    
+    /*
+     * When converting with the String method getBytes(), buffer overflow exception is thrown because
+     * of the way ICU4J is calculating the max bytes per char. This should be changed only on the ICU4J
+     * side to match what the Java method is expecting. The ICU4C size will be left unchanged.
+     * Ticket #9205
+     */
+    public void TestBufferOverflowErrorUsingJavagetBytes() {
+        String charsetName = "ibm-5035";
+        String testCase = "\u7d42";
+        
+        try {
+            testCase.getBytes(charsetName);
+        } catch (Exception ex) {
+            errln("Error calling getBytes(): " + ex);
+        }
+        
+    }
 }