mirror of
https://github.com/curl/curl.git
synced 2026-05-30 07:07:30 +03:00
bufref: rename *memdup() to *memdup0()
To make it clearer to readers of the code that the resulting dup also has a null terminator. Something a "normal" memdup() does not provide. Closes #19833
This commit is contained in:
parent
fe7703a0b3
commit
1def380032
9 changed files with 20 additions and 19 deletions
|
|
@ -54,10 +54,11 @@ specified as `NULL`: this is the case when the referenced buffer is static.
|
|||
|
||||
if `buffer` is NULL, `length` must be zero.
|
||||
|
||||
## `memdup`
|
||||
## `memdup0`
|
||||
|
||||
```c
|
||||
CURLcode Curl_bufref_memdup(struct bufref *br, const void *data, size_t length);
|
||||
CURLcode Curl_bufref_memdup0(struct bufref *br, const void *data,
|
||||
size_t length);
|
||||
```
|
||||
|
||||
Releases the previously referenced buffer, then duplicates the `length`-byte
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ size_t Curl_bufref_len(const struct bufref *br)
|
|||
return br->len;
|
||||
}
|
||||
|
||||
CURLcode Curl_bufref_memdup(struct bufref *br, const void *ptr, size_t len)
|
||||
CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len)
|
||||
{
|
||||
unsigned char *cpy = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len,
|
|||
const char *Curl_bufref_ptr(const struct bufref *br);
|
||||
const unsigned char *Curl_bufref_uptr(const struct bufref *br);
|
||||
size_t Curl_bufref_len(const struct bufref *br);
|
||||
CURLcode Curl_bufref_memdup(struct bufref *br, const void *ptr, size_t len);
|
||||
CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len);
|
||||
void Curl_bufref_free(struct bufref *br);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ static CURLcode FormInfoCopyField(struct bufref *field, size_t len)
|
|||
if(value) {
|
||||
if(!len)
|
||||
len = strlen(value);
|
||||
result = Curl_bufref_memdup(field, value, len);
|
||||
result = Curl_bufref_memdup0(field, value, len);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -260,7 +260,7 @@ static CURLFORMcode FormAddCheck(struct FormInfo *first_form,
|
|||
type = FILE_CONTENTTYPE_DEFAULT;
|
||||
|
||||
/* our contenttype is missing */
|
||||
if(Curl_bufref_memdup(&form->contenttype, type, strlen(type)))
|
||||
if(Curl_bufref_memdup0(&form->contenttype, type, strlen(type)))
|
||||
return CURL_FORMADD_MEMORY;
|
||||
}
|
||||
if(name && form->namelength) {
|
||||
|
|
@ -427,7 +427,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
else {
|
||||
avalue = form_ptr_arg(char *);
|
||||
if(avalue) {
|
||||
if(Curl_bufref_memdup(&curr->value, avalue, strlen(avalue)))
|
||||
if(Curl_bufref_memdup0(&curr->value, avalue, strlen(avalue)))
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
else
|
||||
curr->flags |= HTTPPOST_READFILE;
|
||||
|
|
@ -445,7 +445,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
if(avalue) {
|
||||
form = NewFormInfo();
|
||||
if(!form ||
|
||||
Curl_bufref_memdup(&form->value, avalue, strlen(avalue))) {
|
||||
Curl_bufref_memdup0(&form->value, avalue, strlen(avalue))) {
|
||||
curlx_free(form);
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
}
|
||||
else {
|
||||
if(avalue) {
|
||||
if(Curl_bufref_memdup(&curr->value, avalue, strlen(avalue)))
|
||||
if(Curl_bufref_memdup0(&curr->value, avalue, strlen(avalue)))
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
else
|
||||
curr->flags |= HTTPPOST_FILENAME;
|
||||
|
|
@ -520,7 +520,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
if(curr->flags & HTTPPOST_FILENAME) {
|
||||
if(avalue) {
|
||||
form = NewFormInfo();
|
||||
if(!form || Curl_bufref_memdup(&form->contenttype, avalue,
|
||||
if(!form || Curl_bufref_memdup0(&form->contenttype, avalue,
|
||||
strlen(avalue))) {
|
||||
curlx_free(form);
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
|
|
@ -538,7 +538,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
retval = CURL_FORMADD_OPTION_TWICE;
|
||||
}
|
||||
else if(avalue) {
|
||||
if(Curl_bufref_memdup(&curr->contenttype, avalue, strlen(avalue)))
|
||||
if(Curl_bufref_memdup0(&curr->contenttype, avalue, strlen(avalue)))
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
}
|
||||
else
|
||||
|
|
@ -562,7 +562,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
avalue = form_ptr_arg(char *);
|
||||
if(Curl_bufref_ptr(&curr->showfilename))
|
||||
retval = CURL_FORMADD_OPTION_TWICE;
|
||||
else if(Curl_bufref_memdup(&curr->showfilename, avalue, strlen(avalue)))
|
||||
else if(Curl_bufref_memdup0(&curr->showfilename, avalue, strlen(avalue)))
|
||||
retval = CURL_FORMADD_MEMORY;
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
|
|||
}
|
||||
|
||||
if(output_token.value && output_token.length) {
|
||||
result = Curl_bufref_memdup(out, output_token.value, output_token.length);
|
||||
result = Curl_bufref_memdup0(out, output_token.value, output_token.length);
|
||||
gss_release_buffer(&unused_status, &output_token);
|
||||
}
|
||||
else
|
||||
|
|
@ -285,7 +285,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
|
|||
}
|
||||
|
||||
/* Return the response. */
|
||||
result = Curl_bufref_memdup(out, output_token.value, output_token.length);
|
||||
result = Curl_bufref_memdup0(out, output_token.value, output_token.length);
|
||||
/* Free the output buffer */
|
||||
gss_release_buffer(&unused_status, &output_token);
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
|
|||
}
|
||||
|
||||
if(resp_buf.cbBuffer) {
|
||||
result = Curl_bufref_memdup(out, resp_buf.pvBuffer, resp_buf.cbBuffer);
|
||||
result = Curl_bufref_memdup0(out, resp_buf.pvBuffer, resp_buf.cbBuffer);
|
||||
}
|
||||
else if(mutual_auth)
|
||||
Curl_bufref_set(out, "", 0, NULL);
|
||||
|
|
|
|||
|
|
@ -831,7 +831,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
|
|||
size += hostlen;
|
||||
|
||||
/* Return the binary blob. */
|
||||
result = Curl_bufref_memdup(out, ntlmbuf, size);
|
||||
result = Curl_bufref_memdup0(out, ntlmbuf, size);
|
||||
|
||||
error:
|
||||
curlx_free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
|
|||
}
|
||||
|
||||
/* Return the response. */
|
||||
result = Curl_bufref_memdup(out, ntlm->output_token, type_3_buf.cbBuffer);
|
||||
result = Curl_bufref_memdup0(out, ntlm->output_token, type_3_buf.cbBuffer);
|
||||
Curl_auth_cleanup_ntlm(ntlm);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ static CURLcode test_unit1661(const char *arg)
|
|||
fail_unless(Curl_bufref_len(&bufref) == 13, "Wrong data size returned");
|
||||
|
||||
/**
|
||||
* testing Curl_bufref_memdup
|
||||
* testing Curl_bufref_memdup0
|
||||
*/
|
||||
res = Curl_bufref_memdup(&bufref, "1661", 3);
|
||||
res = Curl_bufref_memdup0(&bufref, "1661", 3);
|
||||
abort_unless(res == CURLE_OK, curl_easy_strerror(res));
|
||||
fail_unless(freecount == 1, "Destructor not called");
|
||||
fail_unless((const char *)bufref.ptr != buffer, "Returned pointer not set");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue