Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: silence -Wsign-conversion, type tidy-ups #13469

Closed
wants to merge 12 commits into from
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 @@ CURLcode 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 @@ CURLcode 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 @@ CURLcode test(char *URL)
res = 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
18 changes: 16 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 Expand Up @@ -220,7 +220,14 @@ static void updateFdSet(struct Sockets *sockets, fd_set* fdset,
{
int i;
for(i = 0; i < sockets->count; ++i) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
FD_SET(sockets->sockets[i], fdset);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
if(*maxFd < sockets->sockets[i] + 1) {
*maxFd = sockets->sockets[i] + 1;
}
Expand Down Expand Up @@ -249,7 +256,14 @@ static int checkFdSet(CURLM *curl,
int i;
int result = 0;
for(i = 0; i < sockets->count; ++i) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(FD_ISSET(sockets->sockets[i], fdset)) {
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
result = socket_action(curl, sockets->sockets[i], evBitmask, name);
if(result)
break;
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
16 changes: 15 additions & 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 Expand Up @@ -188,7 +188,14 @@ static void updateFdSet(struct Sockets *sockets, fd_set* fdset,
{
int i;
for(i = 0; i < sockets->count; ++i) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
FD_SET(sockets->sockets[i], fdset);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
if(*maxFd < sockets->sockets[i] + 1) {
*maxFd = sockets->sockets[i] + 1;
}
Expand All @@ -214,7 +221,14 @@ static void checkFdSet(CURLM *curl, struct Sockets *sockets, fd_set *fdset,
{
int i;
for(i = 0; i < sockets->count; ++i) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(FD_ISSET(sockets->sockets[i], fdset)) {
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
notifyCurl(curl, sockets->sockets[i], evBitmask, name);
}
}
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 @@ CURLcode 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 @@ CURLcode 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
40 changes: 27 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 Expand Up @@ -747,8 +747,15 @@ static bool incoming(curl_socket_t listenfd)
FD_ZERO(&fds_write);
FD_ZERO(&fds_err);

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
/* there's always a socket to wait for */
FD_SET(sockfd, &fds_read);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

do {
/* select() blocking behavior call on blocking descriptors please */
Expand All @@ -765,7 +772,14 @@ static bool incoming(curl_socket_t listenfd)
return FALSE;
}

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(FD_ISSET(sockfd, &fds_read)) {
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
curl_socket_t newfd = accept(sockfd, NULL, NULL);
if(CURL_SOCKET_BAD == newfd) {
error = SOCKERRNO;
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