mirror of
https://github.com/curl/curl.git
synced 2026-08-02 15:40:32 +03:00
lib668: do not assume null-terminator in test input data
For correctness. Did not cause an issue, because the null-terminator is
present.
Also:
- change a size type to avoid casts.
- reuse input length value.
Spotted by GitHub Code Quality
Follow-up to 1e4cb333ef #4826
Closes #22027
This commit is contained in:
parent
7d09426187
commit
8932063828
1 changed files with 5 additions and 4 deletions
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
struct t668_WriteThis {
|
||||
const char *readptr;
|
||||
curl_off_t sizeleft;
|
||||
size_t sizeleft;
|
||||
};
|
||||
|
||||
static size_t t668_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
struct t668_WriteThis *pooh = (struct t668_WriteThis *)userp;
|
||||
size_t len = strlen(pooh->readptr);
|
||||
size_t len = pooh->sizeleft;
|
||||
|
||||
(void)size; /* Always 1 */
|
||||
|
||||
|
|
@ -40,6 +40,7 @@ static size_t t668_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
|
|||
if(len) {
|
||||
memcpy(ptr, pooh->readptr, len);
|
||||
pooh->readptr += len;
|
||||
pooh->sizeleft -= len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
|
@ -76,7 +77,7 @@ static CURLcode test_lib668(const char *URL)
|
|||
|
||||
/* Prepare the callback structures. */
|
||||
pooh1.readptr = testdata;
|
||||
pooh1.sizeleft = (curl_off_t)(sizeof(testdata) - 1);
|
||||
pooh1.sizeleft = sizeof(testdata) - 1;
|
||||
pooh2 = pooh1;
|
||||
|
||||
/* Build the mime tree. */
|
||||
|
|
@ -84,7 +85,7 @@ static CURLcode test_lib668(const char *URL)
|
|||
part = curl_mime_addpart(mime);
|
||||
curl_mime_name(part, "field1");
|
||||
/* Early end of data detection can be done because the data size is known. */
|
||||
curl_mime_data_cb(part, (curl_off_t)(sizeof(testdata) - 1),
|
||||
curl_mime_data_cb(part, (curl_off_t)pooh1.sizeleft,
|
||||
t668_read_cb, NULL, NULL, &pooh1);
|
||||
part = curl_mime_addpart(mime);
|
||||
curl_mime_name(part, "field2");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue