From 0c49ea4ff253ea605e4b6839a4fa32a52d7d8825 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 12 May 2024 21:14:06 +0200 Subject: [PATCH] tests: tidy up types in server code Cherry-picked from #13489 Closes #13610 --- tests/server/mqttd.c | 18 +++++++++--------- tests/server/rtspd.c | 6 +++--- tests/server/sockfilt.c | 6 +++--- tests/server/socksd.c | 2 +- tests/server/tftp.h | 6 +++--- tests/server/tftpd.c | 18 +++++++++--------- tests/server/util.c | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 31918956b..6e24f5cc2 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -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 { @@ -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 */ @@ -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; } @@ -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 */ diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 6aac06ae6..ba6d158ed 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -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 */ diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 27e0ebfed..8d9d13b4f 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -179,7 +179,7 @@ static ssize_t read_wincon(int fd, void *buf, size_t count) return rcount; } - errno = GetLastError(); + errno = (int)GetLastError(); return -1; } #undef read @@ -214,7 +214,7 @@ static ssize_t write_wincon(int fd, const void *buf, size_t count) return wcount; } - errno = GetLastError(); + errno = (int)GetLastError(); return -1; } #undef write @@ -483,7 +483,7 @@ static unsigned int WINAPI select_ws_wait_thread(void *lpParameter) size.LowPart = GetFileSize(handle, &length); if((size.LowPart != INVALID_FILE_SIZE) || (GetLastError() == NO_ERROR)) { - size.HighPart = length; + size.HighPart = (LONG)length; /* get the current position within the file */ pos.QuadPart = 0; pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT); diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 39007e5d7..6fd647faa 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -620,7 +620,7 @@ static curl_socket_t sockit(curl_socket_t fd) memcpy(&response[SOCKS5_BNDADDR + len], &buffer[SOCKS5_DSTADDR + len], sizeof(socksport)); - rc = (send)(fd, (char *)response, (size_t)(len + 6), 0); + rc = (send)(fd, (char *)response, (SEND_TYPE_ARG3)(len + 6), 0); if(rc != (len + 6)) { logmsg("Sending connect response failed!"); return CURL_SOCKET_BAD; diff --git a/tests/server/tftp.h b/tests/server/tftp.h index 70e219721..a3d56b7b3 100644 --- a/tests/server/tftp.h +++ b/tests/server/tftp.h @@ -42,9 +42,9 @@ things build. */ struct tftphdr { - short th_opcode; /* packet type */ - unsigned short th_block; /* all sorts of things */ - char th_data[1]; /* data or error string */ + unsigned short th_opcode; /* packet type */ + unsigned short th_block; /* all sorts of things */ + char th_data[1]; /* data or error string */ } PACKED_STRUCT; #define th_stuff th_block diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 9dd634eb2..afef684a4 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -241,7 +241,8 @@ static int synchnet(curl_socket_t); static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size); -static int validate_access(struct testcase *test, const char *fname, int mode); +static int validate_access(struct testcase *test, + const char *filename, unsigned short mode); static void sendtftp(struct testcase *test, const struct formats *pf); @@ -1073,7 +1074,7 @@ static int parse_servercmd(struct testcase *req) * Validate file access. */ static int validate_access(struct testcase *test, - const char *filename, int mode) + const char *filename, unsigned short mode) { char *ptr; @@ -1183,7 +1184,7 @@ static void sendtftp(struct testcase *test, const struct formats *pf) nak(errno + 100); return; } - sdp->th_opcode = htons((unsigned short)opcode_DATA); + sdp->th_opcode = htons(opcode_DATA); sdp->th_block = htons(sendblock); timeout = 0; #ifdef HAVE_SIGSETJMP @@ -1218,7 +1219,7 @@ send_data: logmsg("read: fail"); return; } - sap->th_opcode = ntohs((unsigned short)sap->th_opcode); + sap->th_opcode = ntohs(sap->th_opcode); sap->th_block = ntohs(sap->th_block); if(sap->th_opcode == opcode_ERROR) { @@ -1261,7 +1262,7 @@ static void recvtftp(struct testcase *test, const struct formats *pf) rap = &ackbuf.hdr; do { timeout = 0; - rap->th_opcode = htons((unsigned short)opcode_ACK); + rap->th_opcode = htons(opcode_ACK); rap->th_block = htons(recvblock); recvblock++; #ifdef HAVE_SIGSETJMP @@ -1290,7 +1291,7 @@ send_ack: logmsg("read: fail"); goto abort; } - rdp->th_opcode = ntohs((unsigned short)rdp->th_opcode); + rdp->th_opcode = ntohs(rdp->th_opcode); rdp->th_block = ntohs(rdp->th_block); if(rdp->th_opcode == opcode_ERROR) goto abort; @@ -1321,8 +1322,7 @@ send_ack: test->ofile = 0; } - rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final" - ack */ + rap->th_opcode = htons(opcode_ACK); /* send the "final" ack */ rap->th_block = htons(recvblock); (void) swrite(peer, &ackbuf.storage[0], 4); #if defined(HAVE_ALARM) && defined(SIGALRM) @@ -1361,7 +1361,7 @@ static void nak(int error) struct errmsg *pe; tp = &buf.hdr; - tp->th_opcode = htons((unsigned short)opcode_ERROR); + tp->th_opcode = htons(opcode_ERROR); tp->th_code = htons((unsigned short)error); for(pe = errmsgs; pe->e_code >= 0; pe++) if(pe->e_code == error) diff --git a/tests/server/util.c b/tests/server/util.c index 74d6d0807..a1355f9c0 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -147,7 +147,7 @@ static const char *win32_strerror(int err, char *buf, size_t buflen) void win32_perror(const char *msg) { char buf[512]; - DWORD err = SOCKERRNO; + int err = SOCKERRNO; win32_strerror(err, buf, sizeof(buf)); if(msg) fprintf(stderr, "%s: ", msg);