summaryrefslogtreecommitdiff
path: root/ext/intl/intl_convertcpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ext/intl/intl_convertcpp.cpp')
-rw-r--r--ext/intl/intl_convertcpp.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/intl/intl_convertcpp.cpp b/ext/intl/intl_convertcpp.cpp
index f52348bc25..3507737616 100644
--- a/ext/intl/intl_convertcpp.cpp
+++ b/ext/intl/intl_convertcpp.cpp
@@ -25,11 +25,16 @@ extern "C" {
}
/* {{{ intl_stringFromChar */
-int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status)
+int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status)
{
+ if(str_len > INT32_MAX) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ ret.setToBogus();
+ return FAILURE;
+ }
//the number of UTF-16 code units is not larger than that of UTF-8 code
//units, + 1 for the terminator
- int32_t capacity = str_len + 1;
+ int32_t capacity = (int32_t)str_len + 1;
//no check necessary -- if NULL will fail ahead
UChar *utf16 = ret.getBuffer(capacity);
@@ -51,7 +56,7 @@ int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCo
* faster than doing intl_convert_utf16_to_utf8(&res, &res_len,
* from.getBuffer(), from.length(), &status),
* but consumes more memory */
-int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status)
+int intl_charFromString(const UnicodeString &from, char **res, size_t *res_len, UErrorCode *status)
{
if (from.isBogus()) {
return FAILURE;
@@ -82,7 +87,7 @@ int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UEr
return FAILURE;
}
(*res)[actual_len] = '\0';
- *res_len = (int)actual_len;
+ *res_len = actual_len;
return SUCCESS;
}