]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/csr2022.cpp
ICU-491.11.2.tar.gz
[apple/icu.git] / icuSources / i18n / csr2022.cpp
index c7165f1c0d3da6f975ed79d2b6dae3508938084c..a890d11bda5fec8c31023b01b7161a9e7945d655 100644 (file)
@@ -1,6 +1,6 @@
 /*
  **********************************************************************
- *   Copyright (C) 2005-2006, International Business Machines
+ *   Copyright (C) 2005-2011, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  **********************************************************************
  */
@@ -43,21 +43,24 @@ int32_t CharsetRecog_2022::match_2022(const uint8_t *text, int32_t textLen, cons
         if(text[i] == 0x1B) {
             escN = 0;
             while(escN < escapeSequences_length) {
-                int32_t seq_length = uprv_strlen((const char *) escapeSequences[escN]);
                 const uint8_t *seq = escapeSequences[escN];
+                int32_t seq_length = (int32_t)uprv_strlen((const char *) seq);
 
-                j = 1;
-                while(j < seq_length) {
-                    if(seq[j] != text[i+j]) {
-                        goto checkEscapes;
+                if (textLen-i >= seq_length) {
+                    j = 1;
+                    while(j < seq_length) {
+                        if(seq[j] != text[i+j]) {
+                            goto checkEscapes;
+                        }
+
+                        j += 1;
                     }
 
-                    j += 1;
+                    hits += 1;
+                    i += seq_length-1;
+                    goto scanInput;
                 }
-
-                hits += 1;
-                i += seq_length-1;
-                goto scanInput;
+                // else we ran out of string to compare this time.
 checkEscapes:
                 escN += 1;
             }
@@ -133,6 +136,8 @@ static const uint8_t escapeSequences_2022CN[][5] = {
     {0x1b, 0x4f, 0x00, 0x00, 0x00},   // SS3
 };
 
+CharsetRecog_2022JP::~CharsetRecog_2022JP() {}
+
 const char *CharsetRecog_2022JP::getName() const
 {
     return "ISO-2022-JP";
@@ -143,6 +148,8 @@ int32_t CharsetRecog_2022JP::match(InputText *textIn)
     return match_2022(textIn->fInputBytes, textIn->fInputLen, escapeSequences_2022JP, ARRAY_SIZE(escapeSequences_2022JP));
 }
 
+CharsetRecog_2022KR::~CharsetRecog_2022KR() {}
+
 const char *CharsetRecog_2022KR::getName() const
 {
     return "ISO-2022-KR";
@@ -153,6 +160,8 @@ int32_t CharsetRecog_2022KR::match(InputText *textIn)
     return match_2022(textIn->fInputBytes, textIn->fInputLen, escapeSequences_2022KR, ARRAY_SIZE(escapeSequences_2022KR));
 }
 
+CharsetRecog_2022CN::~CharsetRecog_2022CN() {}
+
 const char *CharsetRecog_2022CN::getName() const
 {
     return "ISO-2022-CN";