From: Markus Scherer Date: Fri, 17 Feb 2017 18:34:11 +0000 (+0000) Subject: ICU-12410 changes for review feedback X-Git-Tag: release-59-rc~145^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c9606062ddad3222d3d895e30c6b29d7dd0746d;p=icu ICU-12410 changes for review feedback X-SVN-Rev: 39683 --- diff --git a/icu4c/source/common/edits.cpp b/icu4c/source/common/edits.cpp index e36ff745a2d..58a70d5c927 100644 --- a/icu4c/source/common/edits.cpp +++ b/icu4c/source/common/edits.cpp @@ -147,7 +147,9 @@ UBool Edits::growArray() { if (array == stackArray) { newCapacity = 2000; } else if (capacity == INT32_MAX) { - errorCode = U_BUFFER_OVERFLOW_ERROR; + // Not U_BUFFER_OVERFLOW_ERROR because that could be confused on a string transform API + // with a result-string-buffer overflow. + errorCode = U_INDEX_OUTOFBOUNDS_ERROR; return FALSE; } else if (capacity >= (INT32_MAX / 2)) { newCapacity = INT32_MAX; @@ -156,7 +158,7 @@ UBool Edits::growArray() { } // Grow by at least 5 units so that a maximal change record will fit. if ((newCapacity - capacity) < 5) { - errorCode = U_BUFFER_OVERFLOW_ERROR; + errorCode = U_INDEX_OUTOFBOUNDS_ERROR; return FALSE; } uint16_t *newArray = (uint16_t *)uprv_malloc((size_t)newCapacity * 2); diff --git a/icu4c/source/common/unicode/casemap.h b/icu4c/source/common/unicode/casemap.h index 262b5e2ce19..2224172118c 100644 --- a/icu4c/source/common/unicode/casemap.h +++ b/icu4c/source/common/unicode/casemap.h @@ -42,7 +42,7 @@ public: * @param dest A buffer for the result string. The result will be NUL-terminated if * the buffer is large enough. * The contents is undefined in case of failure. - * @param destCapacity The size of the buffer (number of bytes). If it is 0, then + * @param destCapacity The size of the buffer (number of UChars). If it is 0, then * dest may be NULL and the function will only return the length of the result * without writing any of the result string. * @param edits Records edits for index mapping, working with styled text, @@ -50,8 +50,9 @@ public: * This function calls edits->reset() first. edits can be NULL. * @param errorCode Reference to an in/out error code value * which must not indicate a failure before the function call. - * @return The length of the result string, if successful - or in case of a buffer overflow, - * in which case it will be greater than destCapacity. + * @return The length of the result string, if successful. + * When the result would be longer than destCapacity, + * the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set. * * @see u_strToLower * @draft ICU 59 @@ -75,7 +76,7 @@ public: * @param dest A buffer for the result string. The result will be NUL-terminated if * the buffer is large enough. * The contents is undefined in case of failure. - * @param destCapacity The size of the buffer (number of bytes). If it is 0, then + * @param destCapacity The size of the buffer (number of UChars). If it is 0, then * dest may be NULL and the function will only return the length of the result * without writing any of the result string. * @param edits Records edits for index mapping, working with styled text, @@ -83,8 +84,9 @@ public: * This function calls edits->reset() first. edits can be NULL. * @param errorCode Reference to an in/out error code value * which must not indicate a failure before the function call. - * @return The length of the result string, if successful - or in case of a buffer overflow, - * in which case it will be greater than destCapacity. + * @return The length of the result string, if successful. + * When the result would be longer than destCapacity, + * the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set. * * @see u_strToUpper * @draft ICU 59 @@ -120,7 +122,7 @@ public: * @param dest A buffer for the result string. The result will be NUL-terminated if * the buffer is large enough. * The contents is undefined in case of failure. - * @param destCapacity The size of the buffer (number of bytes). If it is 0, then + * @param destCapacity The size of the buffer (number of UChars). If it is 0, then * dest may be NULL and the function will only return the length of the result * without writing any of the result string. * @param edits Records edits for index mapping, working with styled text, @@ -128,8 +130,9 @@ public: * This function calls edits->reset() first. edits can be NULL. * @param errorCode Reference to an in/out error code value * which must not indicate a failure before the function call. - * @return The length of the result string, if successful - or in case of a buffer overflow, - * in which case it will be greater than destCapacity. + * @return The length of the result string, if successful. + * When the result would be longer than destCapacity, + * the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set. * * @see u_strToTitle * @see ucasemap_toTitle @@ -160,7 +163,7 @@ public: * @param dest A buffer for the result string. The result will be NUL-terminated if * the buffer is large enough. * The contents is undefined in case of failure. - * @param destCapacity The size of the buffer (number of bytes). If it is 0, then + * @param destCapacity The size of the buffer (number of UChars). If it is 0, then * dest may be NULL and the function will only return the length of the result * without writing any of the result string. * @param edits Records edits for index mapping, working with styled text, @@ -168,8 +171,9 @@ public: * This function calls edits->reset() first. edits can be NULL. * @param errorCode Reference to an in/out error code value * which must not indicate a failure before the function call. - * @return The length of the result string, if successful - or in case of a buffer overflow, - * in which case it will be greater than destCapacity. + * @return The length of the result string, if successful. + * When the result would be longer than destCapacity, + * the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set. * * @see u_strFoldCase * @draft ICU 59 diff --git a/icu4c/source/common/unicode/ucasemap.h b/icu4c/source/common/unicode/ucasemap.h index c79c252eb39..d14e378a248 100644 --- a/icu4c/source/common/unicode/ucasemap.h +++ b/icu4c/source/common/unicode/ucasemap.h @@ -262,7 +262,7 @@ ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * @param dest A buffer for the result string. The result will be NUL-terminated if * the buffer is large enough. * The contents is undefined in case of failure. - * @param destCapacity The size of the buffer (number of bytes). If it is 0, then + * @param destCapacity The size of the buffer (number of UChars). If it is 0, then * dest may be NULL and the function will only return the length of the result * without writing any of the result string. * @param src The original string. diff --git a/icu4c/source/common/ustrcase.cpp b/icu4c/source/common/ustrcase.cpp index 9c1e570099f..c5fe20ed2d5 100644 --- a/icu4c/source/common/ustrcase.cpp +++ b/icu4c/source/common/ustrcase.cpp @@ -940,10 +940,8 @@ int32_t toUpper(uint32_t options, } } - UBool change; - if (edits == NULL) { - change = TRUE; // common, simple usage - } else { + UBool change = TRUE; + if (edits != NULL) { // Find out first whether we are changing the text. change = src[i] != upper || numYpogegrammeni > 0; int32_t i2 = i + 1;