From: Travis Keep Date: Mon, 26 Nov 2012 21:06:37 +0000 (+0000) Subject: ICU-9669 ures_getStringByKeyWithFallback() to work correctly when returning UChar... X-Git-Tag: milestone-59-0-1~3303 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02197c648ea9b28be342cae8c03c834984cb7171;p=icu ICU-9669 ures_getStringByKeyWithFallback() to work correctly when returning UChar* with embedded nulls. X-SVN-Rev: 32889 --- diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp index 0404e36a821..5bed3fb679a 100644 --- a/icu4c/source/common/uresbund.cpp +++ b/icu4c/source/common/uresbund.cpp @@ -1670,13 +1670,20 @@ ures_getStringByKeyWithFallback(const UResourceBundle *resB, const UChar* retVal = NULL; ures_initStackObject(&stack); ures_getByKeyWithFallback(resB, inKey, &stack, status); - retVal = ures_getString(&stack, len, status); + int32_t length; + retVal = ures_getString(&stack, &length, status); ures_close(&stack); - if ( retVal != NULL && u_strlen(retVal) == 3 && retVal[0] == EMPTY_SET && retVal[1] == EMPTY_SET && retVal[2] == EMPTY_SET ) { + if (U_FAILURE(*status)) { + return NULL; + } + if (length == 3 && retVal[0] == EMPTY_SET && retVal[1] == EMPTY_SET && retVal[2] == EMPTY_SET ) { retVal = NULL; - *len = 0; + length = 0; *status = U_MISSING_RESOURCE_ERROR; } + if (len != NULL) { + *len = length; + } return retVal; }