Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vszakats committed Apr 27, 2024
1 parent c8e0cd1 commit ebc3830
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 95 deletions.
4 changes: 2 additions & 2 deletions tests/http/clients/ws-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "maxlen must be >= 0, got %ld\n", l2);
return 2;
}
plen_min = l1;
plen_max = l2;
plen_min = (size_t)l1;
plen_max = (size_t)l2;
if(plen_max < plen_min) {
fprintf(stderr, "maxlen must be >= minlen, got %ld-%ld\n",
(long)plen_min, (long)plen_max);
Expand Down
4 changes: 2 additions & 2 deletions tests/libtest/lib1537.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int test(char *URL)
raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen);
printf("outlen == %d\n", outlen);
printf("unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
memcmp(raw, a, (size_t)outlen) ? "no" : "YES");
curl_free(raw);

/* deprecated API */
Expand All @@ -70,7 +70,7 @@ int test(char *URL)
outlen = (int)strlen(raw);
printf("[old] outlen == %d\n", outlen);
printf("[old] unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
memcmp(raw, a, (size_t)outlen) ? "no" : "YES");
curl_free(raw);
curl_free(ptr);

Expand Down
3 changes: 2 additions & 1 deletion tests/libtest/lib1597.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ int test(char *URL)
res = (int) TEST_ERR_FAILURE;
goto test_cleanup;
}
n += msnprintf(protolist + n, sizeof(protolist) - n, ",%s", *proto);
n += msnprintf(protolist + n, sizeof(protolist) - (size_t)n, ",%s",
*proto);
if(curl_strequal(*proto, "http"))
httpcode = CURLE_OK;
if(curl_strequal(*proto, "https"))
Expand Down
4 changes: 2 additions & 2 deletions tests/libtest/lib530.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void removeFd(struct Sockets *sockets, curl_socket_t fd, int mention)
if(sockets->sockets[i] == fd) {
if(i < sockets->count - 1)
memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
sizeof(curl_socket_t) * (sockets->count - (i + 1)));
sizeof(curl_socket_t) * (size_t)(sockets->count - (i + 1)));
--sockets->count;
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ static int addFd(struct Sockets *sockets, curl_socket_t fd, const char *what)
}
else if(sockets->count + 1 > sockets->max_count) {
curl_socket_t *ptr = realloc(sockets->sockets, sizeof(curl_socket_t) *
(sockets->max_count + 20));
(size_t)(sockets->max_count + 20));
if(!ptr)
/* cleanup in test_cleanup */
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib571.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream)
}
}
else {
if(memcmp(RTP_DATA, data + i, message_size - i) != 0) {
if(memcmp(RTP_DATA, data + i, (size_t)(message_size - i)) != 0) {
printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
message_size - i, data + i);
/* return failure; */
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib582.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void removeFd(struct Sockets *sockets, curl_socket_t fd, int mention)
if(sockets->sockets[i] == fd) {
if(i < sockets->count - 1)
memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
sizeof(curl_socket_t) * (sockets->count - (i + 1)));
sizeof(curl_socket_t) * (size_t)(sockets->count - (i + 1)));
--sockets->count;
}
}
Expand Down
11 changes: 6 additions & 5 deletions tests/libtest/lib677.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ int test(char *URL)

if(!state) {
CURLcode ec;
ec = curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len);
ec = curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - (size_t)pos,
&len);
if(ec != CURLE_OK) {
fprintf(stderr, "curl_easy_send() failed, with code %d (%s)\n",
(int)ec, curl_easy_strerror(ec));
res = ec;
goto test_cleanup;
}
if(len > 0)
pos += len;
pos += (ssize_t)len;
else
pos = 0;
if(pos == sizeof(cmd) - 1) {
Expand All @@ -100,23 +101,23 @@ int test(char *URL)
}
else if(pos < (ssize_t)sizeof(buf)) {
CURLcode ec;
ec = curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len);
ec = curl_easy_recv(curl, buf + pos, sizeof(buf) - (size_t)pos, &len);
if(ec != CURLE_OK) {
fprintf(stderr, "curl_easy_recv() failed, with code %d (%s)\n",
(int)ec, curl_easy_strerror(ec));
res = ec;
goto test_cleanup;
}
if(len > 0)
pos += len;
pos += (ssize_t)len;
}
if(len <= 0)
sock = CURL_SOCKET_BAD;
}
}

if(state) {
fwrite(buf, pos, 1, stdout);
fwrite(buf, (size_t)pos, 1, stdout);
putchar('\n');
}

Expand Down
26 changes: 13 additions & 13 deletions tests/server/mqttd.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ static void loghex(unsigned char *buffer, ssize_t len)
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width = 0;
int left = sizeof(data);
ssize_t left = sizeof(data);

for(i = 0; i<len && (left >= 0); i++) {
msnprintf(optr, left, "%02x", ptr[i]);
msnprintf(optr, (size_t)left, "%02x", ptr[i]);
width += 2;
optr += 2;
left -= 2;
Expand All @@ -219,10 +219,10 @@ static void logprotocol(mqttdir dir,
ssize_t i;
unsigned char *ptr = buffer;
char *optr = data;
int left = sizeof(data);
ssize_t left = sizeof(data);

for(i = 0; i<len && (left >= 0); i++) {
msnprintf(optr, left, "%02x", ptr[i]);
msnprintf(optr, (size_t)left, "%02x", ptr[i]);
optr += 2;
left -= 2;
}
Expand Down Expand Up @@ -343,10 +343,10 @@ static int disconnect(FILE *dump, curl_socket_t fd)
*/

/* return number of bytes used */
static int encode_length(size_t packetlen,
unsigned char *remlength) /* 4 bytes */
static size_t encode_length(size_t packetlen,
unsigned char *remlength) /* 4 bytes */
{
int bytes = 0;
size_t bytes = 0;
unsigned char encode;

do {
Expand Down Expand Up @@ -396,12 +396,12 @@ static int publish(FILE *dump,
size_t topiclen = strlen(topic);
unsigned char *packet;
size_t payloadindex;
ssize_t remaininglength = topiclen + 2 + payloadlen;
ssize_t packetlen;
ssize_t sendamount;
size_t remaininglength = topiclen + 2 + payloadlen;
size_t packetlen;
size_t sendamount;
ssize_t rc;
unsigned char rembuffer[4];
int encodedlen;
size_t encodedlen;

if(config.excessive_remaining) {
/* manually set illegal remaining length */
Expand Down Expand Up @@ -443,7 +443,7 @@ static int publish(FILE *dump,
loghex(packet, rc);
logprotocol(FROM_SERVER, "PUBLISH", remaininglength, dump, packet, rc);
}
if(rc == packetlen)
if((size_t)rc == packetlen)
return 0;
return 1;
}
Expand All @@ -463,7 +463,7 @@ static int fixedheader(curl_socket_t fd,

/* get the first two bytes */
ssize_t rc = sread(fd, (char *)buffer, 2);
int i;
size_t i;
if(rc < 2) {
logmsg("READ %zd bytes [SHORT!]", rc);
return 1; /* fail */
Expand Down
33 changes: 17 additions & 16 deletions tests/server/rtspd.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ typedef enum {
RPROT_HTTP = 2
} reqprot_t;

#define SET_RTP_PKT_CHN(p,c) ((p)[1] = (unsigned char)((c) & 0xFF))
#define SET_RTP_PKT_CHN(p,c) ((p)[1] = (char)((c) & 0xFF))

#define SET_RTP_PKT_LEN(p,l) (((p)[2] = (unsigned char)(((l) >> 8) & 0xFF)), \
((p)[3] = (unsigned char)((l) & 0xFF)))
#define SET_RTP_PKT_LEN(p,l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \
((p)[3] = (char)((l) & 0xFF)))

struct httprequest {
char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
Expand Down Expand Up @@ -359,7 +359,7 @@ static int ProcessRequest(struct httprequest *req)

/* Make our scratch buffer enough to fit all the
* desired data and one for padding */
rtp_scratch = malloc(rtp_size + 4 + RTP_DATA_SIZE);
rtp_scratch = malloc((size_t)(rtp_size + 4 + RTP_DATA_SIZE));

/* RTP is signalled with a $ */
rtp_scratch[0] = '$';
Expand All @@ -377,15 +377,15 @@ static int ProcessRequest(struct httprequest *req)

if(!req->rtp_buffer) {
req->rtp_buffer = rtp_scratch;
req->rtp_buffersize = rtp_size + 4;
req->rtp_buffersize = (size_t)rtp_size + 4;
}
else {
req->rtp_buffer = realloc(req->rtp_buffer,
req->rtp_buffersize +
rtp_size + 4);
(size_t)rtp_size + 4);
memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch,
rtp_size + 4);
req->rtp_buffersize += rtp_size + 4;
(size_t)rtp_size + 4);
req->rtp_buffersize += (size_t)rtp_size + 4;
free(rtp_scratch);
}
logmsg("rtp_buffersize is %zu, rtp_size is %d.",
Expand Down Expand Up @@ -450,7 +450,7 @@ static int ProcessRequest(struct httprequest *req)
if(req->pipe)
/* we do have a full set, advance the checkindex to after the end of the
headers, for the pipelining case mostly */
req->checkindex += (end - line) + strlen(END_OF_HEADERS);
req->checkindex += (size_t)(end - line) + strlen(END_OF_HEADERS);

/* **** Persistence ****
*
Expand Down Expand Up @@ -486,7 +486,7 @@ static int ProcessRequest(struct httprequest *req)
req->open = FALSE; /* closes connection */
return 1; /* done */
}
req->cl = clen - req->skip;
req->cl = (size_t)clen - (size_t)req->skip;

logmsg("Found Content-Length: %lu in the request", clen);
if(req->skip)
Expand Down Expand Up @@ -563,7 +563,7 @@ static int ProcessRequest(struct httprequest *req)
!strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) {
/* If we have a persistent connection, HTTP version >= 1.1
and GET/HEAD request, enable pipelining. */
req->checkindex = (end - req->reqbuf) + strlen(END_OF_HEADERS);
req->checkindex = (size_t)(end - req->reqbuf) + strlen(END_OF_HEADERS);
req->pipelining = TRUE;
}

Expand All @@ -575,7 +575,7 @@ static int ProcessRequest(struct httprequest *req)
end = strstr(line, END_OF_HEADERS);
if(!end)
break;
req->checkindex += (end - line) + strlen(END_OF_HEADERS);
req->checkindex += (size_t)(end - line) + strlen(END_OF_HEADERS);
req->pipe--;
}

Expand All @@ -587,7 +587,8 @@ static int ProcessRequest(struct httprequest *req)
return 1; /* done */

if(req->cl > 0) {
if(req->cl <= req->offset - (end - req->reqbuf) - strlen(END_OF_HEADERS))
if(req->cl <= req->offset -
(size_t)(end - req->reqbuf) - strlen(END_OF_HEADERS))
return 1; /* done */
else
return 0; /* not complete yet */
Expand Down Expand Up @@ -954,8 +955,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
if(got_exit_signal)
break;

count -= written;
buffer += written;
count -= (size_t)written;
buffer += (size_t)written;
} while(count>0);

/* Send out any RTP data */
Expand All @@ -972,7 +973,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
sendfailure = TRUE;
break;
}
count -= written;
count -= (size_t)written;
} while(count > 0);

free(req->rtp_buffer);
Expand Down
13 changes: 7 additions & 6 deletions tests/server/sockfilt.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ static ssize_t fullread(int filedes, void *buffer, size_t nbytes)

do {
ssize_t rc = read(filedes,
(unsigned char *)buffer + nread, nbytes - nread);
(unsigned char *)buffer + nread,
nbytes - (size_t)nread);

if(got_exit_signal) {
logmsg("signalled to die");
Expand Down Expand Up @@ -281,7 +282,7 @@ static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)

do {
ssize_t wc = write(filedes, (const unsigned char *)buffer + nwrite,
nbytes - nwrite);
nbytes - (size_t)nwrite);

if(got_exit_signal) {
logmsg("signalled to die");
Expand Down Expand Up @@ -354,7 +355,7 @@ static void lograw(unsigned char *buffer, ssize_t len)
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width = 0;
int left = sizeof(data);
size_t left = sizeof(data);

for(i = 0; i<len; i++) {
switch(ptr[i]) {
Expand Down Expand Up @@ -411,7 +412,7 @@ static bool read_data_block(unsigned char *buffer, ssize_t maxlen,
}
logmsg("> %zd bytes data, server => client", *buffer_len);

if(!read_stdin(buffer, *buffer_len))
if(!read_stdin(buffer, (size_t)*buffer_len))
return FALSE;

lograw(buffer, *buffer_len);
Expand Down Expand Up @@ -1104,7 +1105,7 @@ static bool juggle(curl_socket_t *sockfdp,
msnprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len);
if(!write_stdout(data, 10))
return FALSE;
if(!write_stdout(buffer, buffer_len))
if(!write_stdout(buffer, (size_t)buffer_len))
return FALSE;
}
else if(!memcmp("QUIT", buffer, 4)) {
Expand Down Expand Up @@ -1179,7 +1180,7 @@ static bool juggle(curl_socket_t *sockfdp,
msnprintf(data, sizeof(data), "DATA\n%04zx\n", nread_socket);
if(!write_stdout(data, 10))
return FALSE;
if(!write_stdout(buffer, nread_socket))
if(!write_stdout(buffer, (size_t)nread_socket))
return FALSE;

logmsg("< %zd bytes data, client => server", nread_socket);
Expand Down
8 changes: 4 additions & 4 deletions tests/server/socksd.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ static void loghex(unsigned char *buffer, ssize_t len)
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width = 0;
int left = sizeof(data);
ssize_t left = sizeof(data);

for(i = 0; i<len && (left >= 0); i++) {
msnprintf(optr, left, "%02x", ptr[i]);
msnprintf(optr, (size_t)left, "%02x", ptr[i]);
width += 2;
optr += 2;
left -= 2;
Expand Down Expand Up @@ -659,7 +659,7 @@ static int tunnel(struct perclient *cp, fd_set *fds)
(SEND_TYPE_ARG3)nread, 0);
if(nwrite != nread)
return 1;
cp->fromclient += nwrite;
cp->fromclient += (size_t)nwrite;
}
else
return 1;
Expand All @@ -672,7 +672,7 @@ static int tunnel(struct perclient *cp, fd_set *fds)
(SEND_TYPE_ARG3)nread, 0);
if(nwrite != nread)
return 1;
cp->fromremote += nwrite;
cp->fromremote += (size_t)nwrite;
}
else
return 1;
Expand Down

0 comments on commit ebc3830

Please sign in to comment.