summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2018-11-01 02:53:22 -0400
committerJay Satiro <raysatiro@yahoo.com>2018-11-06 03:11:05 -0500
commit28429fb1753d63a659f38577b39e0b5747f28939 (patch)
tree0829bf9ccfc22425b631eef4edd7e7641d05532c
parent53db15ba5524584196eedb3abe8d2e97fb5a3cc0 (diff)
downloadcurl-28429fb1753d63a659f38577b39e0b5747f28939.tar.gz
curl_multibyte: fix a malloc overcalculation
Prior to this change twice as many bytes as necessary were malloc'd when converting wchar to UTF8. To allay confusion in the future I also changed the variable name for the amount of bytes from len to bytes. Closes https://github.com/curl/curl/pull/3209
-rw-r--r--lib/curl_multibyte.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/curl_multibyte.c b/lib/curl_multibyte.c
index e78bb5002..e48334faf 100644
--- a/lib/curl_multibyte.c
+++ b/lib/curl_multibyte.c
@@ -64,13 +64,13 @@ char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w)
char *str_utf8 = NULL;
if(str_w) {
- int str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
- 0, NULL, NULL);
- if(str_utf8_len > 0) {
- str_utf8 = malloc(str_utf8_len * sizeof(wchar_t));
+ int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
+ NULL, 0, NULL, NULL);
+ if(bytes > 0) {
+ str_utf8 = malloc(bytes);
if(str_utf8) {
- if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len,
- NULL, FALSE) == 0) {
+ if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
+ NULL, NULL) == 0) {
free(str_utf8);
return NULL;
}