diff --git a/icu4c/source/common/resbund.cpp b/icu4c/source/common/resbund.cpp index 13fd9de54a0..ca7bfedd13f 100644 --- a/icu4c/source/common/resbund.cpp +++ b/icu4c/source/common/resbund.cpp @@ -249,12 +249,10 @@ ResourceBundle::constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error) { - char name[128]; - int32_t patlen = path.length(); + char name[300]; - if(patlen > 0) { - path.extract(0, patlen, name); - name[patlen] = '\0'; + if(!path.empty()) { + path.extract(name, sizeof(name), 0, error); resource = ures_open(name, locale.getName(), &error); } else { resource = ures_open(0, locale.getName(), &error); diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index 81fcd914f1e..cdcb9bfd9b4 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -763,10 +763,15 @@ umsg_vformat( UMessageFormat *fmt, UErrorCode *status) { - if(U_FAILURE(*status)) + if(status==0 || U_FAILURE(*status)) { return -1; } + if(resultLength<0 || (resultLength>0 && result==0)) { + *status=U_ILLEGAL_ARGUMENT_ERROR; + return -1; + } + int32_t count =0; const Formattable::Type* argTypes = ((MessageFormat*)fmt)->getFormatTypeList(count); Formattable args[MessageFormat::kMaxFormat]; @@ -820,16 +825,7 @@ umsg_vformat( UMessageFormat *fmt, return -1; } - if(result ==NULL || resultLength < resultStr.length()){ - *status = U_BUFFER_OVERFLOW_ERROR; - }else{ - /* copy the resultStr to target buffer */ - //u_strcpy(result, resultStr.getUChars()); - int len = resultStr.length(); - resultStr.extract(0,len,result); - result[len]=0;/* null terminate the string */ - } - return resultStr.length(); + return resultStr.extract(result, resultStr.length(), *status); } U_CAPI void @@ -898,7 +894,6 @@ umsg_vparse(UMessageFormat *fmt, case Formattable::kString: aString = va_arg(ap, UChar*); args[i].getString(temp); - //u_strcpy(aString, temp.getUChars()); len = temp.length(); temp.extract(0,len,aString); aString[len]=0; diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 7fe7e9c9bc2..336da7c94c4 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -687,12 +687,7 @@ unum_getSymbol(UNumberFormat *fmt, } UnicodeString s=((DecimalFormat *)fmt)->getDecimalFormatSymbols()->getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol); - int32_t length=s.length(); - if(buffer!=NULL && length