Commit cadddaed by Edward Thomson

w32: safely cast to int during charset conversion

parent b292c35f
...@@ -25,13 +25,17 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w) ...@@ -25,13 +25,17 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
int utf8_len, utf8_write_len; int utf8_len, utf8_write_len;
size_t new_size; size_t new_size;
if (!len_w) if (!len_w) {
return 0; return 0;
} else if (len_w > INT_MAX) {
git_error_set_oom();
return -1;
}
assert(string_w); assert(string_w);
/* Measure the string necessary for conversion */ /* Measure the string necessary for conversion */
if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, NULL, 0, NULL, NULL)) == 0) if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, NULL, 0, NULL, NULL)) == 0)
return 0; return 0;
assert(utf8_len > 0); assert(utf8_len > 0);
...@@ -43,7 +47,7 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w) ...@@ -43,7 +47,7 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
return -1; return -1;
if ((utf8_write_len = WideCharToMultiByte( if ((utf8_write_len = WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, string_w, len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0) CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0)
return handle_wc_error(); return handle_wc_error();
assert(utf8_write_len == utf8_len); assert(utf8_write_len == utf8_len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment