diff options
author | Jeff Mears <jmears@blizzard.com> | 2021-08-06 14:27:42 -0700 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-08-09 14:08:42 +0200 |
commit | 76e047fc27b3a0b9e6d6d00cacf536e7b7c1b532 (patch) | |
tree | c89d56b7e41d528206edfff8f78568869ed30c4d /lib/strdup.c | |
parent | 3e2a229783b8a8efe88574ec3b6e8c9d060e40e8 (diff) | |
download | curl-76e047fc27b3a0b9e6d6d00cacf536e7b7c1b532.tar.gz |
easy: use a custom implementation of wcsdup on Windows
... so that malloc/free overrides from curl_global_init are used for
wcsdup correctly.
Closes #7540
Diffstat (limited to 'lib/strdup.c')
-rw-r--r-- | lib/strdup.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/strdup.c b/lib/strdup.c index 9af47ea47..05ccdfa8f 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -24,6 +24,10 @@ #include <curl/curl.h> +#ifdef WIN32 +#include <wchar.h> +#endif + #include "strdup.h" #include "curl_memory.h" @@ -50,6 +54,28 @@ char *curlx_strdup(const char *str) } #endif +#ifdef WIN32 +/*************************************************************************** + * + * Curl_wcsdup(source) + * + * Copies the 'source' wchar string to a newly allocated buffer (that is + * returned). + * + * Returns the new pointer or NULL on failure. + * + ***************************************************************************/ +wchar_t *Curl_wcsdup(const wchar_t *src) +{ + size_t length = wcslen(src); + + if(length > (SIZE_T_MAX / sizeof(wchar_t)) - 1) + return (wchar_t *)NULL; /* integer overflow */ + + return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t)); +} +#endif + /*************************************************************************** * * Curl_memdup(source, length) |