lib: add and use Curl_strndup()

The Curl_strndup() function is similar to memdup(), but copies 'n' bytes
then adds a terminating null byte ('\0').

Closes #12251
This commit is contained in:
Daniel Stenberg 2023-11-02 13:47:15 +01:00
parent fdaed85b02
commit d3b3ba35a5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 30 additions and 18 deletions

View file

@ -365,9 +365,7 @@ static void strstore(char **str, const char *newstr, size_t len)
DEBUGASSERT(newstr);
DEBUGASSERT(str);
free(*str);
*str = Curl_memdup(newstr, len + 1);
if(*str)
(*str)[len] = 0;
*str = Curl_strndup(newstr, len);
}
/*