mirror of
https://github.com/curl/curl.git
synced 2026-08-04 20:16:15 +03:00
strdup: do Curl_strndup without strncpy
To avoid (false positive) gcc-13 compiler warnings.
Follow-up to 4855debd8a
Assisted-by: Jay Satiro
Reported-by: Viktor Szakats
Fixes #12258
This commit is contained in:
parent
46878b9e3f
commit
ac57e69b58
3 changed files with 12 additions and 19 deletions
17
lib/http.c
17
lib/http.c
|
|
@ -4608,17 +4608,6 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
/* simple implementation of strndup(), which isn't portable */
|
||||
static char *my_strndup(const char *ptr, size_t len)
|
||||
{
|
||||
char *copy = malloc(len + 1);
|
||||
if(!copy)
|
||||
return NULL;
|
||||
memcpy(copy, ptr, len);
|
||||
copy[len] = '\0';
|
||||
return copy;
|
||||
}
|
||||
|
||||
CURLcode Curl_http_req_make(struct httpreq **preq,
|
||||
const char *method, size_t m_len,
|
||||
const char *scheme, size_t s_len,
|
||||
|
|
@ -4637,17 +4626,17 @@ CURLcode Curl_http_req_make(struct httpreq **preq,
|
|||
goto out;
|
||||
memcpy(req->method, method, m_len);
|
||||
if(scheme) {
|
||||
req->scheme = my_strndup(scheme, s_len);
|
||||
req->scheme = Curl_strndup(scheme, s_len);
|
||||
if(!req->scheme)
|
||||
goto out;
|
||||
}
|
||||
if(authority) {
|
||||
req->authority = my_strndup(authority, a_len);
|
||||
req->authority = Curl_strndup(authority, a_len);
|
||||
if(!req->authority)
|
||||
goto out;
|
||||
}
|
||||
if(path) {
|
||||
req->path = my_strndup(path, p_len);
|
||||
req->path = Curl_strndup(path, p_len);
|
||||
if(!req->path)
|
||||
goto out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue