build: tidy up and dedupe `strdup` functions
No binary (build failed)
—
(log yok)
| @@ -1607,9 +1607,7 @@ check_function_exists("getrlimit" HAVE_GETRLIMIT) | |
| check_function_exists("setlocale" HAVE_SETLOCALE) | |
| check_function_exists("setrlimit" HAVE_SETRLIMIT) | |
| - | if(WIN32) |
| - | set(HAVE_STRDUP 1) # to not define local implementation. curl uses _strdup() on Windows. |
| - | else() |
| + | if(NOT WIN32) |
| check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # net/if.h | |
| check_function_exists("realpath" HAVE_REALPATH) | |
| check_function_exists("sched_yield" HAVE_SCHED_YIELD) | |
| @@ -4160,7 +4160,6 @@ CURL_CHECK_FUNC_SIGNAL | |
| CURL_CHECK_FUNC_SIGSETJMP | |
| CURL_CHECK_FUNC_SOCKET | |
| CURL_CHECK_FUNC_SOCKETPAIR | |
| - | CURL_CHECK_FUNC_STRDUP |
| CURL_CHECK_FUNC_STRERROR_R | |
| case $host in | |
| @@ -4205,6 +4204,7 @@ if test "$curl_cv_native_windows" != "yes"; then | |
| CURL_CHECK_FUNC_INET_PTON | |
| CURL_CHECK_FUNC_STRCASECMP | |
| CURL_CHECK_FUNC_STRCMPI | |
| + | CURL_CHECK_FUNC_STRDUP |
| CURL_CHECK_FUNC_STRICMP | |
| fi | |
| @@ -33,6 +33,7 @@ LIB_CURLX_CFILES = \ | |
| curlx/multibyte.c \ | |
| curlx/nonblock.c \ | |
| curlx/strcopy.c \ | |
| + | curlx/strdup.c \ |
| curlx/strerr.c \ | |
| curlx/strparse.c \ | |
| curlx/timediff.c \ | |
| @@ -55,6 +56,7 @@ LIB_CURLX_HFILES = \ | |
| curlx/nonblock.h \ | |
| curlx/snprintf.h \ | |
| curlx/strcopy.h \ | |
| + | curlx/strdup.h \ |
| curlx/strerr.h \ | |
| curlx/strparse.h \ | |
| curlx/timediff.h \ | |
| @@ -252,7 +254,6 @@ LIB_CFILES = \ | |
| socks_sspi.c \ | |
| splay.c \ | |
| strcase.c \ | |
| - | strdup.c \ |
| strequal.c \ | |
| strerror.c \ | |
| system_win32.c \ | |
| @@ -382,7 +383,6 @@ LIB_HFILES = \ | |
| socks.h \ | |
| splay.h \ | |
| strcase.h \ | |
| - | strdup.h \ |
| strerror.h \ | |
| system_win32.h \ | |
| telnet.h \ | |
| @@ -25,7 +25,7 @@ | |
| #include "urldata.h" | |
| #include "bufref.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #ifdef DEBUGBUILD | |
| #define SIGNATURE 0x5c48e9b2 /* Random pattern. */ | |
| @@ -128,7 +128,7 @@ CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len) | |
| DEBUGASSERT(len <= CURL_MAX_INPUT_LENGTH); | |
| if(ptr) { | |
| - | cpy = Curl_memdup0(ptr, len); |
| + | cpy = curlx_memdup0(ptr, len); |
| if(!cpy) | |
| return CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -69,7 +69,7 @@ | |
| #include "conncache.h" | |
| #include "multihandle.h" | |
| #include "rand.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "system_win32.h" | |
| #include "curlx/nonblock.h" | |
| #include "curlx/version_win32.h" | |
| @@ -483,14 +483,14 @@ CURLcode Curl_parse_interface(const char *input, | |
| input += strlen(if_prefix); | |
| if(!*input) | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| - | *iface = Curl_memdup0(input, len - strlen(if_prefix)); |
| + | *iface = curlx_memdup0(input, len - strlen(if_prefix)); |
| return *iface ? CURLE_OK : CURLE_OUT_OF_MEMORY; | |
| } | |
| else if(!strncmp(host_prefix, input, strlen(host_prefix))) { | |
| input += strlen(host_prefix); | |
| if(!*input) | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| - | *host = Curl_memdup0(input, len - strlen(host_prefix)); |
| + | *host = curlx_memdup0(input, len - strlen(host_prefix)); |
| return *host ? CURLE_OK : CURLE_OUT_OF_MEMORY; | |
| } | |
| else if(!strncmp(if_host_prefix, input, strlen(if_host_prefix))) { | |
| @@ -500,11 +500,11 @@ CURLcode Curl_parse_interface(const char *input, | |
| host_part = memchr(input, '!', len); | |
| if(!host_part || !*(host_part + 1)) | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| - | *iface = Curl_memdup0(input, host_part - input); |
| + | *iface = curlx_memdup0(input, host_part - input); |
| if(!*iface) | |
| return CURLE_OUT_OF_MEMORY; | |
| ++host_part; | |
| - | *host = Curl_memdup0(host_part, len - (host_part - input)); |
| + | *host = curlx_memdup0(host_part, len - (host_part - input)); |
| if(!*host) { | |
| curlx_free(*iface); | |
| *iface = NULL; | |
| @@ -515,7 +515,7 @@ CURLcode Curl_parse_interface(const char *input, | |
| if(!*input) | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| - | *dev = Curl_memdup0(input, len); |
| + | *dev = curlx_memdup0(input, len); |
| return *dev ? CURLE_OK : CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -126,9 +126,6 @@ | |
| /* Define if you have the socket function. */ | |
| #define HAVE_SOCKET 1 | |
| - | /* Define if you have the strdup function. */ |
| - | #define HAVE_STRDUP 1 |
| - | |
| /* Define if you have the utime function. */ | |
| #define HAVE_UTIME 1 | |
| @@ -36,7 +36,7 @@ | |
| #include "curl_get_line.h" | |
| #include "curl_memrchr.h" | |
| #include "parsedate.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "llist.h" | |
| #include "bufref.h" | |
| #include "curlx/strparse.h" | |
| @@ -245,7 +245,7 @@ static char *sanitize_cookie_path(const char *cookie_path, size_t len) | |
| if(len > 1 && cookie_path[len - 1] == '/') | |
| len--; | |
| - | return Curl_memdup0(cookie_path, len); |
| + | return curlx_memdup0(cookie_path, len); |
| } | |
| /* | |
| @@ -264,7 +264,7 @@ static CURLcode strstore(char **str, const char *newstr, size_t len) | |
| len++; | |
| newstr = ""; | |
| } | |
| - | *str = Curl_memdup0(newstr, len); |
| + | *str = curlx_memdup0(newstr, len); |
| if(!*str) | |
| return CURLE_OUT_OF_MEMORY; | |
| return CURLE_OK; | |
| @@ -694,7 +694,7 @@ static CURLcode parse_netscape(struct Cookie *co, | |
| ptr++; | |
| len--; | |
| } | |
| - | co->domain = Curl_memdup0(ptr, len); |
| + | co->domain = curlx_memdup0(ptr, len); |
| if(!co->domain) | |
| return CURLE_OUT_OF_MEMORY; | |
| break; | |
| @@ -737,7 +737,7 @@ static CURLcode parse_netscape(struct Cookie *co, | |
| return CURLE_OK; | |
| break; | |
| case 5: | |
| - | co->name = Curl_memdup0(ptr, len); |
| + | co->name = curlx_memdup0(ptr, len); |
| if(!co->name) | |
| return CURLE_OUT_OF_MEMORY; | |
| else { | |
| @@ -749,7 +749,7 @@ static CURLcode parse_netscape(struct Cookie *co, | |
| } | |
| break; | |
| case 6: | |
| - | co->value = Curl_memdup0(ptr, len); |
| + | co->value = curlx_memdup0(ptr, len); |
| if(!co->value) | |
| return CURLE_OUT_OF_MEMORY; | |
| break; | |
| @@ -1008,7 +1008,7 @@ Curl_cookie_add(struct Curl_easy *data, | |
| goto fail; | |
| /* clone the stack struct into heap */ | |
| - | co = Curl_memdup(&comem, sizeof(comem)); |
| + | co = curlx_memdup(&comem, sizeof(comem)); |
| if(!co) { | |
| co = &comem; | |
| result = CURLE_OUT_OF_MEMORY; | |
| @@ -1077,6 +1077,14 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, | |
| /* Allocator macros */ | |
| + | #ifdef _WIN32 |
| + | #define CURLX_STRDUP_LOW _strdup |
| + | #elif !defined(HAVE_STRDUP) |
| + | #define CURLX_STRDUP_LOW curlx_strdup_low |
| + | #else |
| + | #define CURLX_STRDUP_LOW strdup |
| + | #endif |
| + | |
| #ifdef CURL_MEMDEBUG | |
| #define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) | |
| @@ -1104,11 +1112,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, | |
| #define curlx_realloc Curl_crealloc | |
| #define curlx_free Curl_cfree | |
| #else /* !BUILDING_LIBCURL */ | |
| - | #ifdef _WIN32 |
| - | #define curlx_strdup _strdup |
| - | #else |
| - | #define curlx_strdup strdup |
| - | #endif |
| + | #define curlx_strdup CURLX_STRDUP_LOW |
| #define curlx_malloc malloc | |
| #define curlx_calloc calloc | |
| #define curlx_realloc realloc | |
| @@ -1117,7 +1121,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, | |
| #ifdef _WIN32 | |
| #ifdef UNICODE | |
| - | #define curlx_tcsdup Curl_wcsdup |
| + | #define curlx_tcsdup curlx_wcsdup |
| #else | |
| #define curlx_tcsdup curlx_strdup | |
| #endif | |
| @@ -26,7 +26,7 @@ | |
| #ifdef USE_WINDOWS_SSPI | |
| #include "curl_sspi.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "curlx/multibyte.h" | |
| /* Pointer to SSPI dispatch table */ | |
| @@ -31,56 +31,23 @@ | |
| * be. | |
| */ | |
| - | #include "basename.h" |
| - | /* for curlx_basename() function */ |
| - | |
| - | #include "binmode.h" |
| - | /* "binmode.h" provides macro CURLX_SET_BINMODE() */ |
| - | |
| - | #include "nonblock.h" |
| - | /* "nonblock.h" provides curlx_nonblock() */ |
| - | |
| - | #include "multibyte.h" |
| - | /* "multibyte.h" provides these functions and macros: |
| - | |
| - | curlx_convert_UTF8_to_wchar() |
| - | curlx_convert_wchar_to_UTF8() |
| - | curlx_convert_UTF8_to_tchar() |
| - | curlx_convert_tchar_to_UTF8() |
| - | */ |
| - | |
| - | #include "version_win32.h" |
| - | /* provides curlx_verify_windows_version() */ |
| - | |
| - | #include "strerr.h" |
| - | /* The curlx_strerror() function */ |
| - | |
| - | #include "strparse.h" |
| - | /* The curlx_str_* parsing functions */ |
| - | |
| - | #include "strcopy.h" |
| - | /* curlx_strcopy */ |
| - | |
| - | #include "dynbuf.h" |
| - | /* The curlx_dyn_* functions */ |
| - | |
| - | #include "fopen.h" |
| - | /* The curlx_f* functions */ |
| - | |
| - | #include "base64.h" |
| - | #include "timeval.h" |
| - | #include "timediff.h" |
| - | |
| - | #include "wait.h" |
| - | /* for curlx_wait_ms */ |
| - | |
| - | #include "winapi.h" |
| - | /* for curlx_winapi_strerror */ |
| - | |
| - | #include "inet_pton.h" |
| - | /* for curlx_inet_pton */ |
| - | |
| - | #include "inet_ntop.h" |
| - | /* for curlx_inet_ntop */ |
| + | #include "base64.h" /* for curlx_base64* */ |
| + | #include "basename.h" /* for curlx_basename() */ |
| + | #include "binmode.h" /* for macro CURLX_SET_BINMODE() */ |
| + | #include "dynbuf.h" /* for curlx_dyn_*() */ |
| + | #include "fopen.h" /* for curlx_f*() */ |
| + | #include "inet_ntop.h" /* for curlx_inet_ntop() */ |
| + | #include "inet_pton.h" /* for curlx_inet_pton() */ |
| + | #include "multibyte.h" /* for curlx_convert_*() */ |
| + | #include "nonblock.h" /* for curlx_nonblock() */ |
| + | #include "strcopy.h" /* for curlx_strcopy() */ |
| + | #include "strdup.h" /* for curlx_memdup*() and curlx_tcsdup() */ |
| + | #include "strerr.h" /* for curlx_strerror() */ |
| + | #include "strparse.h" /* for curlx_str_* parsing functions */ |
| + | #include "timediff.h" /* for timediff_t type and related functions */ |
| + | #include "timeval.h" /* for curlx_now type and related functions */ |
| + | #include "version_win32.h" /* for curlx_verify_windows_version() */ |
| + | #include "wait.h" /* for curlx_wait_ms() */ |
| + | #include "winapi.h" /* for curlx_winapi_strerror() */ |
| #endif /* HEADER_CURL_CURLX_H */ | |
| @@ -102,7 +102,7 @@ static CURLcode dyn_nappend(struct dynbuf *s, | |
| } | |
| if(a != s->allc) { | |
| - | /* this logic is not using Curl_saferealloc() to make the tool not have to |
| + | /* this logic is not using curlx_saferealloc() to make the tool not have to |
| include that as well when it uses this code */ | |
| void *p = curlx_realloc(s->bufr, a); | |
| if(!p) { | |
| @@ -21,7 +21,7 @@ | |
| * SPDX-License-Identifier: curl | |
| * | |
| ***************************************************************************/ | |
| - | #include "curl_setup.h" |
| + | #include "../curl_setup.h" |
| #ifdef _WIN32 | |
| #include <wchar.h> | |
| @@ -29,51 +29,49 @@ | |
| #include "strdup.h" | |
| - | #ifndef HAVE_STRDUP |
| - | char *Curl_strdup(const char *str) |
| - | { |
| - | size_t len; |
| - | char *newstr; |
| - | |
| - | if(!str) |
| - | return NULL; |
| - | |
| - | len = strlen(str) + 1; |
| - | |
| - | newstr = curlx_malloc(len); |
| - | if(!newstr) |
| - | return NULL; |
| - | |
| - | memcpy(newstr, str, len); |
| - | return newstr; |
| - | } |
| - | #endif |
| - | |
| #ifdef _WIN32 | |
| /*************************************************************************** | |
| * | |
| - | * Curl_wcsdup(source) |
| + | * curlx_wcsdup(source) |
| * | |
| * Copies the 'source' wchar string to a newly allocated buffer (that is | |
| - | * returned). |
| + | * returned). Used by macro curlx_tcsdup(). |
| * | |
| * Returns the new pointer or NULL on failure. | |
| * | |
| ***************************************************************************/ | |
| - | wchar_t *Curl_wcsdup(const wchar_t *src) |
| + | wchar_t *curlx_wcsdup(const wchar_t *src) |
| { | |
| size_t length = wcslen(src); | |
| if(length > (SIZE_MAX / sizeof(wchar_t)) - 1) | |
| return (wchar_t *)NULL; /* integer overflow */ | |
| - | return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t)); |
| + | return (wchar_t *)curlx_memdup(src, (length + 1) * sizeof(wchar_t)); |
| + | } |
| + | #elif !defined(HAVE_STRDUP) |
| + | char *curlx_strdup_low(const char *str) |
| + | { |
| + | size_t len; |
| + | char *newstr; |
| + | |
| + | if(!str) |
| + | return NULL; |
| + | |
| + | len = strlen(str) + 1; |
| + | |
| + | newstr = curlx_malloc(len); |
| + | if(!newstr) |
| + | return NULL; |
| + | |
| + | memcpy(newstr, str, len); |
| + | return newstr; |
| } | |
| #endif | |
| /*************************************************************************** | |
| * | |
| - | * Curl_memdup(source, length) |
| + | * curlx_memdup(source, length) |
| * | |
| * Copies the 'source' data to a newly allocated buffer (that is | |
| * returned). Copies 'length' bytes. | |
| @@ -81,7 +79,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src) | |
| * Returns the new pointer or NULL on failure. | |
| * | |
| ***************************************************************************/ | |
| - | void *Curl_memdup(const void *src, size_t length) |
| + | void *curlx_memdup(const void *src, size_t length) |
| { | |
| void *buffer = curlx_malloc(length); | |
| if(!buffer) | |
| @@ -94,7 +92,7 @@ void *Curl_memdup(const void *src, size_t length) | |
| /*************************************************************************** | |
| * | |
| - | * Curl_memdup0(source, length) |
| + | * curlx_memdup0(source, length) |
| * | |
| * Copies the 'source' string to a newly allocated buffer (that is returned). | |
| * Copies 'length' bytes then adds a null-terminator. | |
| @@ -102,7 +100,7 @@ void *Curl_memdup(const void *src, size_t length) | |
| * Returns the new pointer or NULL on failure. | |
| * | |
| ***************************************************************************/ | |
| - | void *Curl_memdup0(const char *src, size_t length) |
| + | void *curlx_memdup0(const char *src, size_t length) |
| { | |
| char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL; | |
| if(!buf) | |
| @@ -117,7 +115,7 @@ void *Curl_memdup0(const char *src, size_t length) | |
| /*************************************************************************** | |
| * | |
| - | * Curl_saferealloc(ptr, size) |
| + | * curlx_saferealloc(ptr, size) |
| * | |
| * Does a normal curlx_realloc(), but will free the data pointer if the realloc | |
| * fails. If 'size' is non-zero, it will free the data and return a failure. | |
| @@ -129,7 +127,7 @@ void *Curl_memdup0(const char *src, size_t length) | |
| * Returns the new pointer or NULL on failure. | |
| * | |
| ***************************************************************************/ | |
| - | void *Curl_saferealloc(void *ptr, size_t size) |
| + | void *curlx_saferealloc(void *ptr, size_t size) |
| { | |
| void *datap = curlx_realloc(ptr, size); | |
| if(size && !datap) | |
| @@ -1,5 +1,5 @@ | |
| - | #ifndef HEADER_CURL_STRDUP_H |
| - | #define HEADER_CURL_STRDUP_H |
| + | #ifndef HEADER_CURLX_STRDUP_H |
| + | #define HEADER_CURLX_STRDUP_H |
| /*************************************************************************** | |
| * _ _ ____ _ | |
| * Project ___| | | | _ \| | | |
| @@ -23,15 +23,14 @@ | |
| * SPDX-License-Identifier: curl | |
| * | |
| ***************************************************************************/ | |
| - | #include "curl_setup.h" |
| + | #include "../curl_setup.h" |
| - | #ifndef HAVE_STRDUP |
| - | char *Curl_strdup(const char *str); |
| - | #endif |
| #ifdef _WIN32 | |
| - | wchar_t *Curl_wcsdup(const wchar_t *src); |
| + | wchar_t *curlx_wcsdup(const wchar_t *src); /* for curlx_tcsdup() */ |
| + | #elif !defined(HAVE_STRDUP) |
| + | char *curlx_strdup_low(const char *str); |
| #endif | |
| - | void *Curl_memdup(const void *src, size_t buffer_length); |
| - | void *Curl_saferealloc(void *ptr, size_t size); |
| - | void *Curl_memdup0(const char *src, size_t length); |
| - | #endif /* HEADER_CURL_STRDUP_H */ |
| + | void *curlx_memdup(const void *src, size_t buffer_length); |
| + | void *curlx_memdup0(const char *src, size_t length); |
| + | void *curlx_saferealloc(void *ptr, size_t size); |
| + | #endif /* HEADER_CURLX_STRDUP_H */ |
| @@ -33,7 +33,7 @@ | |
| #include "multiif.h" | |
| #include "url.h" | |
| #include "connect.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "curlx/dynbuf.h" | |
| #include "escape.h" | |
| #include "urlapi-int.h" | |
| @@ -592,7 +592,7 @@ static DOHcode doh_store_https(const unsigned char *doh, int index, | |
| /* silently ignore RRs over the limit */ | |
| if(d->numhttps_rrs < DOH_MAX_HTTPS) { | |
| struct dohhttps_rr *h = &d->https_rrs[d->numhttps_rrs]; | |
| - | h->val = Curl_memdup(&doh[index], len); |
| + | h->val = curlx_memdup(&doh[index], len); |
| if(!h->val) | |
| return DOH_OUT_OF_MEM; | |
| h->len = len; | |
| @@ -51,7 +51,7 @@ | |
| #include "url.h" | |
| #include "getinfo.h" | |
| #include "hostip.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "easyif.h" | |
| #include "multiif.h" | |
| #include "multi_ev.h" | |
| @@ -94,19 +94,6 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT; | |
| #endif | |
| - | /* |
| - | * strdup (and other memory functions) is redefined in complicated |
| - | * ways, but at this point it must be defined as the system-supplied strdup |
| - | * so the callback pointer is initialized correctly. |
| - | */ |
| - | #ifdef _WIN32 |
| - | #define system_strdup _strdup |
| - | #elif defined(HAVE_STRDUP) |
| - | #define system_strdup strdup |
| - | #else |
| - | #define system_strdup Curl_strdup |
| - | #endif |
| - | |
| #if defined(_MSC_VER) && defined(_DLL) | |
| # pragma warning(push) | |
| # pragma warning(disable:4232) /* MSVC extension, dllimport identity */ | |
| @@ -119,7 +106,7 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT; | |
| curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc; | |
| curl_free_callback Curl_cfree = (curl_free_callback)free; | |
| curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc; | |
| - | curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup; |
| + | curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW; |
| curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc; | |
| #if defined(_MSC_VER) && defined(_DLL) | |
| @@ -144,7 +131,7 @@ static CURLcode global_init(long flags, bool memoryfuncs) | |
| Curl_cmalloc = (curl_malloc_callback)malloc; | |
| Curl_cfree = (curl_free_callback)free; | |
| Curl_crealloc = (curl_realloc_callback)realloc; | |
| - | Curl_cstrdup = (curl_strdup_callback)system_strdup; |
| + | Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW; |
| Curl_ccalloc = (curl_calloc_callback)calloc; | |
| } | |
| @@ -919,9 +906,9 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src) | |
| if(src->set.postfieldsize == -1) | |
| dst->set.str[i] = curlx_strdup(src->set.str[i]); | |
| else | |
| - | /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */ |
| - | dst->set.str[i] = Curl_memdup(src->set.str[i], |
| - | curlx_sotouz(src->set.postfieldsize)); |
| + | /* postfieldsize is curl_off_t, curlx_memdup() takes a size_t ... */ |
| + | dst->set.str[i] = curlx_memdup(src->set.str[i], |
| + | curlx_sotouz(src->set.postfieldsize)); |
| if(!dst->set.str[i]) | |
| return CURLE_OUT_OF_MEMORY; | |
| /* point to the new copy */ | |
| @@ -31,7 +31,7 @@ struct Curl_easy; | |
| #include "urldata.h" /* for struct Curl_easy */ | |
| #include "mime.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "bufref.h" | |
| #include "curlx/fopen.h" | |
| @@ -696,7 +696,7 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) | |
| if(!name || !len) | |
| return curl_mime_name(part, name); | |
| - | zname = Curl_memdup0(name, len); |
| + | zname = curlx_memdup0(name, len); |
| if(!zname) | |
| return CURLE_OUT_OF_MEMORY; | |
| res = curl_mime_name(part, zname); | |
| @@ -65,7 +65,7 @@ | |
| #include "multiif.h" | |
| #include "url.h" | |
| #include "http_proxy.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "curlx/strerr.h" | |
| #include "curlx/strparse.h" | |
| @@ -3195,7 +3195,7 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, | |
| ptr++; | |
| for(start = ptr; *ptr && *ptr != ' '; ptr++) | |
| ; | |
| - | os = Curl_memdup0(start, ptr - start); |
| + | os = curlx_memdup0(start, ptr - start); |
| if(!os) | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -3578,7 +3578,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, | |
| else | |
| /* file is url-decoded */ | |
| pathLen -= ftpc->file ? strlen(ftpc->file) : 0; | |
| - | ftpc->prevpath = Curl_memdup0(rawPath, pathLen); |
| + | ftpc->prevpath = curlx_memdup0(rawPath, pathLen); |
| } | |
| else | |
| ftpc->prevpath = NULL; /* no path */ | |
| @@ -77,7 +77,7 @@ | |
| #include "http2.h" | |
| #include "cfilters.h" | |
| #include "connect.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "altsvc.h" | |
| #include "hsts.h" | |
| #include "rtsp.h" | |
| @@ -200,7 +200,7 @@ static CURLcode copy_custom_value(const char *header, char **valp) | |
| curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE); | |
| curlx_str_trimblanks(&out); | |
| - | *valp = Curl_memdup0(curlx_str(&out), curlx_strlen(&out)); |
| + | *valp = curlx_memdup0(curlx_str(&out), curlx_strlen(&out)); |
| if(*valp) | |
| return CURLE_OK; | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -227,7 +227,7 @@ char *Curl_copy_header_value(const char *header) | |
| !curlx_str_single(&header, ':')) { | |
| curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE); | |
| curlx_str_trimblanks(&out); | |
| - | return Curl_memdup0(curlx_str(&out), curlx_strlen(&out)); |
| + | return curlx_memdup0(curlx_str(&out), curlx_strlen(&out)); |
| } | |
| /* bad input, should never happen */ | |
| DEBUGASSERT(0); | |
| @@ -4659,17 +4659,17 @@ CURLcode Curl_http_req_make(struct httpreq **preq, | |
| #pragma GCC diagnostic pop | |
| #endif | |
| if(scheme) { | |
| - | req->scheme = Curl_memdup0(scheme, s_len); |
| + | req->scheme = curlx_memdup0(scheme, s_len); |
| if(!req->scheme) | |
| goto out; | |
| } | |
| if(authority) { | |
| - | req->authority = Curl_memdup0(authority, a_len); |
| + | req->authority = curlx_memdup0(authority, a_len); |
| if(!req->authority) | |
| goto out; | |
| } | |
| if(path) { | |
| - | req->path = Curl_memdup0(path, p_len); |
| + | req->path = curlx_memdup0(path, p_len); |
| if(!req->path) | |
| goto out; | |
| } | |
| @@ -27,7 +27,7 @@ | |
| #include "urldata.h" | |
| #include "strcase.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "http_aws_sigv4.h" | |
| #include "curl_sha256.h" | |
| #include "transfer.h" | |
| @@ -405,7 +405,7 @@ static CURLcode make_headers(struct Curl_easy *data, | |
| if(data->state.aptr.host) { | |
| /* remove /r/n as the separator for canonical request must be '\n' */ | |
| size_t pos = strcspn(data->state.aptr.host, "\n\r"); | |
| - | fullhost = Curl_memdup0(data->state.aptr.host, pos); |
| + | fullhost = curlx_memdup0(data->state.aptr.host, pos); |
| } | |
| else | |
| fullhost = curl_maprintf("host:%s", hostname); | |
| @@ -29,7 +29,7 @@ | |
| #include "httpsrr.h" | |
| #include "connect.h" | |
| #include "curl_trc.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len, | |
| unsigned char *alpns) | |
| @@ -92,7 +92,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, | |
| if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */ | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| curlx_free(hi->ipv4hints); | |
| - | hi->ipv4hints = Curl_memdup(val, vlen); |
| + | hi->ipv4hints = curlx_memdup(val, vlen); |
| if(!hi->ipv4hints) | |
| return CURLE_OUT_OF_MEMORY; | |
| hi->ipv4hints_len = vlen; | |
| @@ -102,7 +102,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, | |
| if(!vlen) | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| curlx_free(hi->echconfiglist); | |
| - | hi->echconfiglist = Curl_memdup(val, vlen); |
| + | hi->echconfiglist = curlx_memdup(val, vlen); |
| if(!hi->echconfiglist) | |
| return CURLE_OUT_OF_MEMORY; | |
| hi->echconfiglist_len = vlen; | |
| @@ -112,7 +112,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, | |
| if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */ | |
| return CURLE_BAD_FUNCTION_ARGUMENT; | |
| curlx_free(hi->ipv6hints); | |
| - | hi->ipv6hints = Curl_memdup(val, vlen); |
| + | hi->ipv6hints = curlx_memdup(val, vlen); |
| if(!hi->ipv6hints) | |
| return CURLE_OUT_OF_MEMORY; | |
| hi->ipv6hints_len = vlen; | |
| @@ -134,7 +134,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, | |
| struct Curl_https_rrinfo * | |
| Curl_httpsrr_dup_move(struct Curl_https_rrinfo *rrinfo) | |
| { | |
| - | struct Curl_https_rrinfo *dup = Curl_memdup(rrinfo, sizeof(*rrinfo)); |
| + | struct Curl_https_rrinfo *dup = curlx_memdup(rrinfo, sizeof(*rrinfo)); |
| if(dup) | |
| memset(rrinfo, 0, sizeof(*rrinfo)); | |
| return dup; | |
| @@ -30,7 +30,7 @@ struct Curl_easy; | |
| #include "sendf.h" | |
| #include "curl_trc.h" | |
| #include "transfer.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "curlx/basename.h" | |
| #include "curlx/strcopy.h" | |
| #include "curlx/fopen.h" | |
| @@ -1281,7 +1281,7 @@ CURLcode curl_mime_data(curl_mimepart *part, const char *ptr, size_t datasize) | |
| if(datasize == CURL_ZERO_TERMINATED) | |
| datasize = strlen(ptr); | |
| - | part->data = Curl_memdup0(ptr, datasize); |
| + | part->data = curlx_memdup0(ptr, datasize); |
| if(!part->data) | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -71,7 +71,7 @@ | |
| #include "bufref.h" | |
| #include "curl_sasl.h" | |
| #include "curl_md5.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| /* Authentication type flags */ | |
| #define POP3_TYPE_CLEARTEXT (1 << 0) | |
| @@ -826,7 +826,7 @@ static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data, | |
| therefore do not use APOP authentication. */ | |
| if(at) { | |
| /* dupe the timestamp */ | |
| - | pop3c->apoptimestamp = Curl_memdup0(lt, timestamplen); |
| + | pop3c->apoptimestamp = curlx_memdup0(lt, timestamplen); |
| if(!pop3c->apoptimestamp) | |
| return CURLE_OUT_OF_MEMORY; | |
| /* Store the APOP capability */ | |
| @@ -38,7 +38,7 @@ | |
| #include "select.h" | |
| #include "connect.h" | |
| #include "cfilters.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "bufref.h" | |
| #include "curlx/strparse.h" | |
| @@ -1028,7 +1028,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header) | |
| */ | |
| /* Copy the id substring into a new buffer */ | |
| - | data->set.str[STRING_RTSP_SESSION_ID] = Curl_memdup0(start, idlen); |
| + | data->set.str[STRING_RTSP_SESSION_ID] = curlx_memdup0(start, idlen); |
| if(!data->set.str[STRING_RTSP_SESSION_ID]) | |
| return CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -46,7 +46,7 @@ | |
| #include "altsvc.h" | |
| #include "hsts.h" | |
| #include "tftp.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "escape.h" | |
| #include "bufref.h" | |
| @@ -1920,7 +1920,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, | |
| mark that postfields is used rather than read function or form | |
| data. | |
| */ | |
| - | char *p = Curl_memdup0(ptr, pflen); |
| + | char *p = curlx_memdup0(ptr, pflen); |
| if(!p) | |
| return CURLE_OUT_OF_MEMORY; | |
| else { | |
| @@ -33,7 +33,7 @@ | |
| #include "connect.h" | |
| #include "curlx/nonblock.h" | |
| #include "socks.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #if defined(__GNUC__) && defined(__APPLE__) | |
| #pragma GCC diagnostic push | |
| @@ -135,7 +135,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, | |
| /* prepare service name */ | |
| if(strchr(serviceptr, '/')) { | |
| service.length = serviceptr_length; | |
| - | service.value = Curl_memdup(serviceptr, service.length); |
| + | service.value = curlx_memdup(serviceptr, service.length); |
| if(!service.value) | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -374,7 +374,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, | |
| } | |
| else { | |
| gss_send_token.length = 1; | |
| - | gss_send_token.value = Curl_memdup(&gss_enc, gss_send_token.length); |
| + | gss_send_token.value = curlx_memdup(&gss_enc, gss_send_token.length); |
| if(!gss_send_token.value) { | |
| Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -94,7 +94,7 @@ | |
| #include "http_proxy.h" | |
| #include "conncache.h" | |
| #include "multihandle.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "setopt.h" | |
| #include "altsvc.h" | |
| #include "curlx/dynbuf.h" | |
| @@ -2431,13 +2431,13 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len, | |
| (size_t)(login + len - osep)) - 1 : 0); | |
| /* Clone the user portion buffer, which can be zero length */ | |
| - | ubuf = Curl_memdup0(login, ulen); |
| + | ubuf = curlx_memdup0(login, ulen); |
| if(!ubuf) | |
| goto error; | |
| /* Clone the password portion buffer */ | |
| if(psep) { | |
| - | pbuf = Curl_memdup0(&psep[1], plen); |
| + | pbuf = curlx_memdup0(&psep[1], plen); |
| if(!pbuf) | |
| goto error; | |
| } | |
| @@ -2446,7 +2446,7 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len, | |
| if(optionsp) { | |
| char *obuf = NULL; | |
| if(olen) { | |
| - | obuf = Curl_memdup0(&osep[1], olen); |
| + | obuf = curlx_memdup0(&osep[1], olen); |
| if(!obuf) | |
| goto error; | |
| } | |
| @@ -30,7 +30,7 @@ | |
| #include "escape.h" | |
| #include "curlx/inet_pton.h" | |
| #include "curlx/inet_ntop.h" | |
| - | #include "strdup.h" |
| + | #include "curlx/strdup.h" |
| #include "idn.h" | |
| #include "curlx/strparse.h" | |
| #include "curl_memrchr.h" | |
| @@ -1025,7 +1025,7 @@ static CURLUcode handle_fragment(CURLU *u, const char *fragment, | |
| u->fragment = curlx_dyn_ptr(&enc); | |
| } | |
| else { | |
| - | u->fragment = Curl_memdup0(fragment + 1, fraglen - 1); |
| + | u->fragment = curlx_memdup0(fragment + 1, fraglen - 1); |
| if(!u->fragment) | |
| return CURLUE_OUT_OF_MEMORY; | |
| } | |
| @@ -1049,7 +1049,7 @@ static CURLUcode handle_query(CURLU *u, const char *query, | |
| u->query = curlx_dyn_ptr(&enc); | |
| } | |
| else { | |
| - | u->query = Curl_memdup0(query + 1, qlen - 1); |
| + | u->query = curlx_memdup0(query + 1, qlen - 1); |
| if(!u->query) | |
| return CURLUE_OUT_OF_MEMORY; | |
| } | |
| @@ -1083,7 +1083,7 @@ static CURLUcode handle_path(CURLU *u, const char *path, | |
| } | |
| else { | |
| if(!u->path) { | |
| - | u->path = Curl_memdup0(path, pathlen); |
| + | u->path = curlx_memdup0(path, pathlen); |
| if(!u->path) | |
| return CURLUE_OUT_OF_MEMORY; | |
| path = u->path; | |
| @@ -1364,7 +1364,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, | |
| bool urlencode = (flags & CURLU_URLENCODE) ? 1 : 0; | |
| bool punycode = (flags & CURLU_PUNYCODE) && (what == CURLUPART_HOST); | |
| bool depunyfy = (flags & CURLU_PUNY2IDN) && (what == CURLUPART_HOST); | |
| - | char *part = Curl_memdup0(ptr, partlen); |
| + | char *part = curlx_memdup0(ptr, partlen); |
| *partp = NULL; | |
| if(!part) | |
| return CURLUE_OUT_OF_MEMORY; | |
| @@ -32,7 +32,7 @@ | |
| #include "digest.h" | |
| #include "../curlx/multibyte.h" | |
| #include "../curl_trc.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../strcase.h" | |
| #include "../strerror.h" | |
| @@ -351,7 +351,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, | |
| } | |
| /* Store the challenge for use later */ | |
| - | digest->input_token = (BYTE *)Curl_memdup(chlg, chlglen + 1); |
| + | digest->input_token = (BYTE *)curlx_memdup(chlg, chlglen + 1); |
| if(!digest->input_token) | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -612,7 +612,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, | |
| Curl_sspi_free_identity(p_identity); | |
| } | |
| - | resp = Curl_memdup0((const char *)output_token, output_token_len); |
| + | resp = curlx_memdup0((const char *)output_token, output_token_len); |
| curlx_free(output_token); | |
| if(!resp) { | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -38,7 +38,7 @@ | |
| #include "../curl_trc.h" | |
| #include "../curl_ntlm_core.h" | |
| #include "../rand.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../curl_endian.h" | |
| /* NTLM buffer fixed size, large enough for long user + host + domain */ | |
| @@ -267,8 +267,8 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data, | |
| } | |
| curlx_free(ntlm->target_info); /* replace any previous data */ | |
| - | ntlm->target_info = Curl_memdup(&type2[target_info_offset], |
| - | target_info_len); |
| + | ntlm->target_info = curlx_memdup(&type2[target_info_offset], |
| + | target_info_len); |
| if(!ntlm->target_info) | |
| return CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -28,7 +28,7 @@ | |
| #include "vauth.h" | |
| #include "../curl_ntlm_core.h" | |
| #include "../curl_trc.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| /* | |
| * Curl_auth_is_ntlm_supported() | |
| @@ -201,8 +201,8 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data, | |
| } | |
| /* Store the challenge for later use */ | |
| - | ntlm->input_token = Curl_memdup0(Curl_bufref_ptr(type2), |
| - | Curl_bufref_len(type2)); |
| + | ntlm->input_token = curlx_memdup0(Curl_bufref_ptr(type2), |
| + | Curl_bufref_len(type2)); |
| if(!ntlm->input_token) | |
| return CURLE_OUT_OF_MEMORY; | |
| ntlm->input_token_len = Curl_bufref_len(type2); | |
| @@ -50,7 +50,7 @@ | |
| #include "../parsedate.h" | |
| #include "../connect.h" /* for the connect timeout */ | |
| #include "../progress.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../curlx/fopen.h" | |
| #include "x509asn1.h" | |
| @@ -723,7 +723,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, | |
| "and store in cache", sdata_len, alpn ? alpn : "-", | |
| earlydata_max); | |
| if(quic_tp && quic_tp_len) { | |
| - | qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); |
| + | qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len); |
| if(!qtp_clone) { | |
| curlx_free(sdata); | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -65,7 +65,7 @@ | |
| #include "vtls_scache.h" | |
| #include "x509asn1.h" | |
| #include "../connect.h" /* for the connect timeout */ | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../curl_sha256.h" | |
| /* ALPN for http2 */ | |
| @@ -521,8 +521,8 @@ static CURLcode mbed_connect_step1(struct Curl_cfilter *cf, | |
| provided the exact length). The function accepts PEM or DER | |
| formats, but we cannot assume if the user passed in a PEM | |
| format cert that it is null-terminated. */ | |
| - | unsigned char *newblob = Curl_memdup0(ca_info_blob->data, |
| - | ca_info_blob->len); |
| + | unsigned char *newblob = curlx_memdup0(ca_info_blob->data, |
| + | ca_info_blob->len); |
| if(!newblob) | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -620,8 +620,8 @@ static CURLcode mbed_connect_step1(struct Curl_cfilter *cf, | |
| provided the exact length). The function accepts PEM or DER | |
| formats, but we cannot assume if the user passed in a PEM | |
| format cert that it is null-terminated. */ | |
| - | unsigned char *newblob = Curl_memdup0(ssl_cert_blob->data, |
| - | ssl_cert_blob->len); |
| + | unsigned char *newblob = curlx_memdup0(ssl_cert_blob->data, |
| + | ssl_cert_blob->len); |
| if(!newblob) | |
| return CURLE_OUT_OF_MEMORY; | |
| ret = mbedtls_x509_crt_parse(&backend->clicert, newblob, | |
| @@ -61,7 +61,7 @@ | |
| #include "../curlx/strerr.h" | |
| #include "../curlx/strparse.h" | |
| #include "../curlx/strcopy.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "apple.h" | |
| #include <openssl/rand.h> | |
| @@ -2703,7 +2703,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, | |
| earlydata_max = SSL_SESSION_get_max_early_data(session); | |
| #endif | |
| if(quic_tp && quic_tp_len) { | |
| - | qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); |
| + | qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len); |
| if(!qtp_clone) { | |
| result = CURLE_OUT_OF_MEMORY; | |
| goto out; | |
| @@ -42,7 +42,7 @@ | |
| #include "vtls_scache.h" | |
| #include "../curl_trc.h" | |
| #include "../connect.h" /* for the connect timeout */ | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../strerror.h" | |
| #include "../select.h" /* for the socket readiness */ | |
| #include "../curlx/fopen.h" | |
| @@ -70,7 +70,7 @@ | |
| #include "../connect.h" | |
| #include "../select.h" | |
| #include "../setopt.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../curlx/strcopy.h" | |
| #ifdef USE_APPLE_SECTRUST | |
| @@ -2039,7 +2039,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf, | |
| result = CURLE_SSL_CONNECT_ERROR; | |
| goto out; | |
| } | |
| - | connssl->negotiated.alpn = Curl_memdup0((const char *)proto, proto_len); |
| + | connssl->negotiated.alpn = curlx_memdup0((const char *)proto, proto_len); |
| if(!connssl->negotiated.alpn) | |
| return CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -29,7 +29,7 @@ | |
| #include "../curl_trc.h" | |
| #include "vtls_scache.h" | |
| #include "vtls_spack.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #ifndef UINT16_MAX | |
| #define UINT16_MAX 0xffff | |
| @@ -152,7 +152,7 @@ static CURLcode spack_decstr16(char **val, const uint8_t **src, | |
| return r; | |
| if(end - *src < slen) | |
| return CURLE_READ_ERROR; | |
| - | *val = Curl_memdup0((const char *)(*src), slen); |
| + | *val = curlx_memdup0((const char *)(*src), slen); |
| *src += slen; | |
| return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY; | |
| } | |
| @@ -182,7 +182,7 @@ static CURLcode spack_decdata16(uint8_t **val, size_t *val_len, | |
| return r; | |
| if(end - *src < data_len) | |
| return CURLE_READ_ERROR; | |
| - | *val = Curl_memdup0((const char *)(*src), data_len); |
| + | *val = curlx_memdup0((const char *)(*src), data_len); |
| *val_len = data_len; | |
| *src += data_len; | |
| return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY; | |
| @@ -60,7 +60,7 @@ | |
| #include "keylog.h" | |
| #include "../connect.h" /* for the connect timeout */ | |
| #include "../progress.h" | |
| - | #include "../strdup.h" |
| + | #include "../curlx/strdup.h" |
| #include "../curlx/strcopy.h" | |
| #include "x509asn1.h" | |
| @@ -443,7 +443,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, | |
| goto out; | |
| } | |
| if(quic_tp && quic_tp_len) { | |
| - | qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); |
| + | qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len); |
| if(!qtp_clone) { | |
| curlx_free(sdata); | |
| return CURLE_OUT_OF_MEMORY; | |
| @@ -40,6 +40,7 @@ CURLX_CFILES = \ | |
| ../lib/curlx/multibyte.c \ | |
| ../lib/curlx/nonblock.c \ | |
| ../lib/curlx/strcopy.c \ | |
| + | ../lib/curlx/strdup.c \ |
| ../lib/curlx/strerr.c \ | |
| ../lib/curlx/strparse.c \ | |
| ../lib/curlx/timediff.c \ | |
| @@ -58,6 +59,7 @@ CURLX_HFILES = \ | |
| ../lib/curlx/nonblock.h \ | |
| ../lib/curlx/snprintf.h \ | |
| ../lib/curlx/strcopy.h \ | |
| + | ../lib/curlx/strdup.h \ |
| ../lib/curlx/strerr.h \ | |
| ../lib/curlx/strparse.h \ | |
| ../lib/curlx/timediff.h \ | |
| @@ -108,7 +110,6 @@ CURL_CFILES = \ | |
| tool_setopt.c \ | |
| tool_ssls.c \ | |
| tool_stderr.c \ | |
| - | tool_strdup.c \ |
| tool_urlglob.c \ | |
| tool_util.c \ | |
| tool_vms.c \ | |
| @@ -154,7 +155,6 @@ CURL_HFILES = \ | |
| tool_setup.h \ | |
| tool_ssls.h \ | |
| tool_stderr.h \ | |
| - | tool_strdup.h \ |
| tool_urlglob.h \ | |
| tool_util.h \ | |
| tool_version.h \ | |
| @@ -34,7 +34,6 @@ | |
| #include "tool_cb_wrt.h" | |
| #include "tool_operate.h" | |
| #include "tool_libinfo.h" | |
| - | #include "tool_strdup.h" |
| #ifdef _WIN32 | |
| #define BOLD "\x1b[1m" | |
| @@ -98,7 +97,7 @@ static void write_linked_location(CURL *curl, const char *location, | |
| goto locout; | |
| /* Create a null-terminated and whitespace-stripped copy of Location: */ | |
| - | copyloc = memdup0(loc, llen); |
| + | copyloc = curlx_memdup0(loc, llen); |
| if(!copyloc) | |
| goto locout; | |
| @@ -154,7 +153,7 @@ static char *parse_filename(const char *ptr, size_t len, char stop) | |
| char *p; | |
| char *q; | |
| - | copy = memdup0(ptr, len); |
| + | copy = curlx_memdup0(ptr, len); |
| if(!copy) | |
| return NULL; | |
| @@ -36,7 +36,6 @@ | |
| #include "tool_main.h" | |
| #include "tool_stderr.h" | |
| #include "tool_help.h" | |
| - | #include "tool_strdup.h" |
| #include "var.h" | |
| #define ALLOW_BLANK TRUE | |
| @@ -70,7 +69,7 @@ static ParameterError getstrn(char **str, const char *val, | |
| if(!allowblank && !val[0]) | |
| return PARAM_BLANK_STRING; | |
| - | *str = memdup0(val, len); |
| + | *str = curlx_memdup0(val, len); |
| if(!*str) | |
| return PARAM_NO_MEM; | |
| @@ -62,12 +62,6 @@ extern FILE *tool_stderr; | |
| /* define what to use for unprintable characters */ | |
| #define UNPRINTABLE_CHAR '.' | |
| - | #ifndef HAVE_STRDUP |
| - | #include "tool_strdup.h" |
| - | #undef Curl_strdup |
| - | #define Curl_strdup tool_strdup |
| - | #endif |
| - | |
| #ifndef tool_nop_stmt | |
| #define tool_nop_stmt do {} while(0) | |
| #endif | |
| @@ -1,55 +0,0 @@ | |
| - | /*************************************************************************** |
| - | * _ _ ____ _ |
| - | * Project ___| | | | _ \| | |
| - | * / __| | | | |_) | | |
| - | * | (__| |_| | _ <| |___ |
| - | * \___|\___/|_| \_\_____| |
| - | * |
| - | * Copyright (C) Daniel Stenberg, <[email protected]>, et al. |
| - | * |
| - | * This software is licensed as described in the file COPYING, which |
| - | * you should have received as part of this distribution. The terms |
| - | * are also available at https://curl.se/docs/copyright.html. |
| - | * |
| - | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| - | * copies of the Software, and permit persons to whom the Software is |
| - | * furnished to do so, under the terms of the COPYING file. |
| - | * |
| - | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| - | * KIND, either express or implied. |
| - | * |
| - | * SPDX-License-Identifier: curl |
| - | * |
| - | ***************************************************************************/ |
| - | #include "tool_strdup.h" |
| - | |
| - | #ifndef HAVE_STRDUP |
| - | char *tool_strdup(const char *str) |
| - | { |
| - | size_t len; |
| - | char *newstr; |
| - | |
| - | if(!str) |
| - | return (char *)NULL; |
| - | |
| - | len = strlen(str) + 1; |
| - | |
| - | newstr = curlx_malloc(len); |
| - | if(!newstr) |
| - | return (char *)NULL; |
| - | |
| - | memcpy(newstr, str, len); |
| - | return newstr; |
| - | } |
| - | #endif |
| - | |
| - | char *memdup0(const char *data, size_t len) |
| - | { |
| - | char *p = curlx_malloc(len + 1); |
| - | if(!p) |
| - | return NULL; |
| - | if(len) |
| - | memcpy(p, data, len); |
| - | p[len] = 0; |
| - | return p; |
| - | } |
| @@ -1,33 +0,0 @@ | |
| - | #ifndef HEADER_TOOL_STRDUP_H |
| - | #define HEADER_TOOL_STRDUP_H |
| - | /*************************************************************************** |
| - | * _ _ ____ _ |
| - | * Project ___| | | | _ \| | |
| - | * / __| | | | |_) | | |
| - | * | (__| |_| | _ <| |___ |
| - | * \___|\___/|_| \_\_____| |
| - | * |
| - | * Copyright (C) Daniel Stenberg, <[email protected]>, et al. |
| - | * |
| - | * This software is licensed as described in the file COPYING, which |
| - | * you should have received as part of this distribution. The terms |
| - | * are also available at https://curl.se/docs/copyright.html. |
| - | * |
| - | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| - | * copies of the Software, and permit persons to whom the Software is |
| - | * furnished to do so, under the terms of the COPYING file. |
| - | * |
| - | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| - | * KIND, either express or implied. |
| - | * |
| - | * SPDX-License-Identifier: curl |
| - | * |
| - | ***************************************************************************/ |
| - | #include "tool_setup.h" |
| - | |
| - | #ifndef HAVE_STRDUP |
| - | extern char *tool_strdup(const char *str); |
| - | #endif |
| - | char *memdup0(const char *data, size_t len); |
| - | |
| - | #endif /* HEADER_TOOL_STRDUP_H */ |
| @@ -27,7 +27,6 @@ | |
| #include "tool_doswin.h" | |
| #include "tool_urlglob.h" | |
| #include "tool_vms.h" | |
| - | #include "tool_strdup.h" |
| static CURLcode globerror(struct URLGlob *glob, const char *err, | |
| size_t pos, CURLcode error) | |
| @@ -49,7 +48,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len) | |
| if(!pat->c.set.elem) | |
| return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); | |
| - | pat->c.set.elem[0] = memdup0(fixed, len); |
| + | pat->c.set.elem[0] = curlx_memdup0(fixed, len); |
| if(!pat->c.set.elem[0]) { | |
| tool_safefree(pat->c.set.elem); | |
| return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); | |
| @@ -28,7 +28,6 @@ | |
| #include "tool_msgs.h" | |
| #include "tool_paramhlp.h" | |
| #include "tool_writeout_json.h" | |
| - | #include "tool_strdup.h" |
| #include "var.h" | |
| #define MAX_EXPAND_CONTENT 10000000 | |
| @@ -190,7 +189,7 @@ static ParameterError varfunc(char *c, /* content */ | |
| curlx_free(c); | |
| clen = curlx_dyn_len(out); | |
| - | c = memdup0(curlx_dyn_ptr(out), clen); |
| + | c = curlx_memdup0(curlx_dyn_ptr(out), clen); |
| if(!c) { | |
| err = PARAM_NO_MEM; | |
| break; | |
| @@ -357,7 +356,7 @@ static ParameterError addvariable(const char *name, | |
| memcpy(p->name, name, nlen); | |
| /* the null termination byte is already present from above */ | |
| - | p->content = contalloc ? content : memdup0(content, clen); |
| + | p->content = contalloc ? content : curlx_memdup0(content, clen); |
| if(p->content) { | |
| p->clen = clen; | |
| @@ -52,12 +52,7 @@ static void *custom_malloc(size_t size) | |
| static char *custom_strdup(const char *ptr) | |
| { | |
| seen++; | |
| - | #ifdef _WIN32 |
| - | return _strdup(ptr); |
| - | #else |
| - | /* !checksrc! disable BANNEDFUNC 1 */ |
| - | return strdup(ptr); |
| - | #endif |
| + | return CURLX_STRDUP_LOW(ptr); |
| } | |
| static void *custom_realloc(void *ptr, size_t size) | |
| @@ -36,11 +36,7 @@ | |
| curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc; | |
| curl_free_callback Curl_cfree = (curl_free_callback)free; | |
| curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc; | |
| - | #ifdef _WIN32 |
| - | curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)_strdup; |
| - | #else |
| - | curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup; |
| - | #endif |
| + | curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW; |
| curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc; | |
| #if defined(_MSC_VER) && defined(_DLL) | |
| @@ -16,5 +16,4 @@ allowfunc send | |
| allowfunc snprintf | |
| allowfunc socket | |
| allowfunc sscanf | |
| - | allowfunc strdup |
| allowfunc vsnprintf | |
| @@ -69,10 +69,6 @@ extern const struct entry_s s_entries[]; | |
| # define snprintf _snprintf | |
| #endif | |
| - | #ifdef _WIN32 |
| - | # define strdup _strdup |
| - | #endif |
| - | |
| #ifdef _WIN32 | |
| # define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n) | |
| #elif defined(HAVE_STRCASECMP) | |
| @@ -610,7 +610,7 @@ static int validate_access(struct testcase *test, | |
| (long)our_getpid()); | |
| logmsg("Are-we-friendly question received"); | |
| - | test->buffer = strdup(weare); |
| + | test->buffer = curlx_strdup(weare); |
| test->rptr = test->buffer; /* set read pointer */ | |
| test->bufsize = count; /* set total count */ | |
| test->rcount = count; /* set data left to read */ | |