strdup: remove the memchr check from Curl_strndup
It makes it possible to clone a binary chunk of data. Closes #12453
This commit is contained in:
parent
c0dd06ecb3
commit
63cdaefbc3
@ -104,18 +104,14 @@ void *Curl_memdup(const void *src, size_t length)
|
|||||||
* Curl_strndup(source, length)
|
* Curl_strndup(source, length)
|
||||||
*
|
*
|
||||||
* Copies the 'source' string to a newly allocated buffer (that is returned).
|
* 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
|
* Copies 'length' bytes then adds a null terminator.
|
||||||
* null terminator.
|
|
||||||
*
|
*
|
||||||
* Returns the new pointer or NULL on failure.
|
* Returns the new pointer or NULL on failure.
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void *Curl_strndup(const char *src, size_t length)
|
void *Curl_strndup(const char *src, size_t length)
|
||||||
{
|
{
|
||||||
char *buf = memchr(src, '\0', length);
|
char *buf = malloc(length + 1);
|
||||||
if(buf)
|
|
||||||
length = buf - src;
|
|
||||||
buf = malloc(length + 1);
|
|
||||||
if(!buf)
|
if(!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
memcpy(buf, src, length);
|
memcpy(buf, src, length);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user