From: Markus Scherer Date: Fri, 27 Jan 2012 00:13:45 +0000 (+0000) Subject: ICU-9059 check U16_APPEND() isError flag to avoid compiler warnings, even if we do... X-Git-Tag: milestone-59-0-1~4109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0497efa1ad3cceb8d9c769be636dfb60dfe697a7;p=icu ICU-9059 check U16_APPEND() isError flag to avoid compiler warnings, even if we do not need it X-SVN-Rev: 31272 --- diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index 9de2ca6d207..717d092a0ad 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1,7 +1,7 @@ /* ****************************************************************************** -* Copyright (C) 1999-2011, International Business Machines Corporation and * -* others. All Rights Reserved. * +* Copyright (C) 1999-2012, International Business Machines Corporation and +* others. All Rights Reserved. ****************************************************************************** * * File unistr.cpp @@ -211,7 +211,11 @@ UnicodeString::UnicodeString(UChar32 ch) int32_t i = 0; UBool isError = FALSE; U16_APPEND(fUnion.fStackBuffer, i, US_STACKBUF_SIZE, ch, isError); - fShortLength = (int8_t)i; + // We test isError so that the compiler does not complain that we don't. + // If isError then i==0 which is what we want anyway. + if(!isError) { + fShortLength = (int8_t)i; + } } UnicodeString::UnicodeString(const UChar *text) @@ -1244,7 +1248,9 @@ UnicodeString::replace(int32_t start, int32_t count = 0; UBool isError = FALSE; U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError); - return doReplace(start, _length, buffer, 0, count); + // We test isError so that the compiler does not complain that we don't. + // If isError then count==0 which turns the doReplace() into a no-op anyway. + return isError ? *this : doReplace(start, _length, buffer, 0, count); } UnicodeString& @@ -1253,7 +1259,9 @@ UnicodeString::append(UChar32 srcChar) { int32_t _length = 0; UBool isError = FALSE; U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError); - return doReplace(length(), 0, buffer, 0, _length); + // We test isError so that the compiler does not complain that we don't. + // If isError then _length==0 which turns the doReplace() into a no-op anyway. + return isError ? *this : doReplace(length(), 0, buffer, 0, _length); } UnicodeString&