]> granicus.if.org Git - icu/commitdiff
ICU-12849 Title Casing, incorrect length returned when preflighting with a NULL outpu...
authorAndy Heninger <andy.heninger@gmail.com>
Thu, 1 Dec 2016 01:41:40 +0000 (01:41 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Thu, 1 Dec 2016 01:41:40 +0000 (01:41 +0000)
X-SVN-Rev: 39518

icu4c/source/common/ucasemap.cpp
icu4c/source/common/ustrcase.cpp
icu4c/source/test/intltest/strcase.cpp
icu4c/source/test/intltest/ustrtest.h

index 4d59f7d8f7bfebb077c685ad9ed43d5aece1fec3..0576a26ddd1c86b6e8cd3262cdad4f96992e2bd3 100644 (file)
@@ -422,6 +422,9 @@ ucasemap_internalUTF8ToTitle(const UCaseMap *csm,
                                 src, &csc,
                                 titleLimit, idx,
                                 pErrorCode);
+                        if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
+                            *pErrorCode=U_ZERO_ERROR;
+                        }
                         if(U_FAILURE(*pErrorCode)) {
                             return destIndex;
                         }
index aee35361cb79ac0acab9b14fe1d69564757ace78..8f594ec27851fc0512a891b68c0f0ceb301a4b99 100644 (file)
@@ -305,6 +305,9 @@ ustrcase_internalToTitle(const UCaseMap *csm,
                                 src, &csc,
                                 titleLimit, idx,
                                 pErrorCode);
+                        if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
+                            *pErrorCode=U_ZERO_ERROR;
+                        }
                         if(U_FAILURE(*pErrorCode)) {
                             return destIndex;
                         }
index 34f3e4ac22ce6c15d5ef2b3c0d8c0a531336a5e2..7054b7f1e7a350b2df2b81f75c61ba08bb98fe0e 100644 (file)
@@ -49,6 +49,7 @@ StringCaseTest::runIndexedTest(int32_t index, UBool exec, const char *&name, cha
     TESTCASE_AUTO(TestGreekUpper);
     TESTCASE_AUTO(TestLongUpper);
     TESTCASE_AUTO(TestMalformedUTF8);
+    TESTCASE_AUTO(TestBufferOverflow);
     TESTCASE_AUTO_END;
 }
 
@@ -815,3 +816,35 @@ void StringCaseTest::TestMalformedUTF8() {
               errorCode.errorName(), (int)destLength, dest[0]);
     }
 }
+
+void StringCaseTest::TestBufferOverflow() {
+    // Ticket #12849, incorrect result from Title Case preflight operation, 
+    // when buffer overflow error is expected.
+    IcuTestErrorCode errorCode(*this, "TestBufferOverflow");
+    LocalUCaseMapPointer csm(ucasemap_open("en", 0, errorCode));
+    if (errorCode.isFailure()) {
+        errln("ucasemap_open(English) failed - %s", errorCode.errorName());
+        return;
+    }
+
+    UnicodeString data("hello world");
+    int32_t result = ucasemap_toTitle(csm.getAlias(), NULL, 0, data.getBuffer(), data.length(), errorCode);
+    if (errorCode.get() != U_BUFFER_OVERFLOW_ERROR || result != data.length()) {
+        errln("%s:%d ucasemap_toTitle(\"hello world\") failed: "
+              "expected (U_BUFFER_OVERFLOW_ERROR, %d), got (%s, %d)",
+              __FILE__, __LINE__, data.length(), errorCode.errorName(), result);
+    }
+    errorCode.reset();
+
+#if U_HAVE_STD_STRING
+    std::string data_utf8;
+    data.toUTF8String(data_utf8);
+    result = ucasemap_utf8ToTitle(csm.getAlias(), NULL, 0, data_utf8.c_str(), data_utf8.length(), errorCode);
+    if (errorCode.get() != U_BUFFER_OVERFLOW_ERROR || result != (int32_t)data_utf8.length()) {
+        errln("%s:%d ucasemap_toTitle(\"hello world\") failed: "
+              "expected (U_BUFFER_OVERFLOW_ERROR, %d), got (%s, %d)",
+              __FILE__, __LINE__, data_utf8.length(), errorCode.errorName(), result);
+    }
+    errorCode.reset();
+#endif  // U_HAVE_STD_STRING
+}
index ef3f6cff8ac8acfed4c44fae798749362b503363..37b3a88ea957c00ba5099a0ad5054fbbe2bcb68a 100644 (file)
@@ -112,6 +112,7 @@ public:
     void TestGreekUpper();
     void TestLongUpper();
     void TestMalformedUTF8();
+    void TestBufferOverflow();
 
 private:
     void assertGreekUpper(const char *s, const char *expected);