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:
Viktor Szakats 2026-06-15 14:41:19 +02:00
parent 7d09426187
commit 8932063828
No known key found for this signature in database

View file

@ -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");