]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
strdup: remove the memchr check from Curl_strndup
authorDaniel Stenberg <daniel@haxx.se>
Tue, 5 Dec 2023 14:55:35 +0000 (15:55 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 7 Dec 2023 07:47:28 +0000 (08:47 +0100)
It makes it possible to clone a binary chunk of data.

Closes #12453

lib/strdup.c

index 2578441c317287c8dacf5212611a1b11a908d70f..50f0656b91be3159c89f00fbce9e86c08c306362 100644 (file)
@@ -104,18 +104,14 @@ void *Curl_memdup(const void *src, size_t length)
  * Curl_strndup(source, length)
  *
  * Copies the 'source' string to a newly allocated buffer (that is returned).
- * Copies not more than 'length' bytes (up to a null terminator) then adds a
- * null terminator.
+ * Copies 'length' bytes then adds a null terminator.
  *
  * Returns the new pointer or NULL on failure.
  *
  ***************************************************************************/
 void *Curl_strndup(const char *src, size_t length)
 {
-  char *buf = memchr(src, '\0', length);
-  if(buf)
-    length = buf - src;
-  buf = malloc(length + 1);
+  char *buf = malloc(length + 1);
   if(!buf)
     return NULL;
   memcpy(buf, src, length);