aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/strdup.c
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-10-18 20:31:38 +0300
committerGitHub <noreply@github.com>2024-10-18 20:31:38 +0300
commit2a74bac2d2d3bccb4e10120f1ead805640ec9dd0 (patch)
tree047e4818ced5aaf73f58517629e5260b5291f9f0 /contrib/libs/curl/lib/strdup.c
parent2d9656823e9521d8c29ea4c9a1d0eab78391abfc (diff)
parent3d834a1923bbf9403cd4a448e7f32b670aa4124f (diff)
downloadydb-2a74bac2d2d3bccb4e10120f1ead805640ec9dd0.tar.gz
Merge pull request #10502 from ydb-platform/mergelibs-241016-1210
Library import 241016-1210
Diffstat (limited to 'contrib/libs/curl/lib/strdup.c')
-rw-r--r--contrib/libs/curl/lib/strdup.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/contrib/libs/curl/lib/strdup.c b/contrib/libs/curl/lib/strdup.c
index 299c9cc36b..2578441c31 100644
--- a/contrib/libs/curl/lib/strdup.c
+++ b/contrib/libs/curl/lib/strdup.c
@@ -101,17 +101,21 @@ void *Curl_memdup(const void *src, size_t length)
/***************************************************************************
*
- * Curl_memdup0(source, length)
+ * Curl_strndup(source, length)
*
* Copies the 'source' string to a newly allocated buffer (that is returned).
- * Copies 'length' bytes then adds a null terminator.
+ * Copies not more than 'length' bytes (up to a null terminator) then adds a
+ * null terminator.
*
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
-void *Curl_memdup0(const char *src, size_t length)
+void *Curl_strndup(const char *src, size_t length)
{
- char *buf = malloc(length + 1);
+ char *buf = memchr(src, '\0', length);
+ if(buf)
+ length = buf - src;
+ buf = malloc(length + 1);
if(!buf)
return NULL;
memcpy(buf, src, length);