From f1597c86b1c435ed279d2fd325c7dfb4619960a2 Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 3 Mar 2014 16:46:48 -0800 Subject: [PATCH] fix clang -Wconversion except -Wsign-conversion --- ctaocrypt/benchmark/benchmark.c | 2 +- ctaocrypt/src/asn.c | 4 ++-- ctaocrypt/src/coding.c | 16 ++++++++-------- ctaocrypt/test/test.c | 2 +- cyassl/test.h | 10 +++++----- examples/client/client.c | 4 ++-- examples/echoclient/echoclient.c | 2 +- examples/echoserver/echoserver.c | 4 ++-- examples/server/server.c | 4 ++-- src/internal.c | 6 +++--- src/sniffer.c | 14 +++++++------- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index 4b4a3fa6d..72503131b 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -998,7 +998,7 @@ void bench_eccKeyAgree(void) /* make dummy digest */ for (i = 0; i < (int)sizeof(digest); i++) - digest[i] = i; + digest[i] = (byte)i; start = current_time(1); diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index e5c23f15d..f0e93b949 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -3210,11 +3210,11 @@ static void DecodeSubjKeyId(byte* input, int sz, DecodedCert* cert) length--; if (length == 2) { - cert->extKeyUsage = (input[idx] << 8) | input[idx+1]; + cert->extKeyUsage = (word16)((input[idx] << 8) | input[idx+1]); cert->extKeyUsage >>= unusedBits; } else if (length == 1) - cert->extKeyUsage = (input[idx] << 1); + cert->extKeyUsage = (word16)(input[idx] << 1); return; } diff --git a/ctaocrypt/src/coding.c b/ctaocrypt/src/coding.c index 8add2d59a..c18c7ee05 100644 --- a/ctaocrypt/src/coding.c +++ b/ctaocrypt/src/coding.c @@ -95,9 +95,9 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) e3 = (e3 == PAD) ? 0 : base64Decode[e3 - 0x2B]; e4 = (e4 == PAD) ? 0 : base64Decode[e4 - 0x2B]; - b1 = (e1 << 2) | (e2 >> 4); - b2 = ((e2 & 0xF) << 4) | (e3 >> 2); - b3 = ((e3 & 0x3) << 6) | e4; + b1 = (byte)((e1 << 2) | (e2 >> 4)); + b2 = (byte)(((e2 & 0xF) << 4) | (e3 >> 2)); + b3 = (byte)(((e3 & 0x3) << 6) | e4); out[i++] = b1; if (!pad3) @@ -251,8 +251,8 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out, /* encoded idx */ byte e1 = b1 >> 2; - byte e2 = ((b1 & 0x3) << 4) | (b2 >> 4); - byte e3 = ((b2 & 0xF) << 2) | (b3 >> 6); + byte e2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4)); + byte e3 = (byte)(((b2 & 0xF) << 2) | (b3 >> 6)); byte e4 = b3 & 0x3F; /* store */ @@ -281,8 +281,8 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out, byte b2 = (twoBytes) ? in[j++] : 0; byte e1 = b1 >> 2; - byte e2 = ((b1 & 0x3) << 4) | (b2 >> 4); - byte e3 = (b2 & 0xF) << 2; + byte e2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4)); + byte e3 = (byte)((b2 & 0xF) << 2); ret = CEscape(escaped, e1, out, &i, *outLen, 0); if (ret == 0) @@ -375,7 +375,7 @@ int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) if (b == BAD || b2 == BAD) return ASN_INPUT_E; - out[outIdx++] = (b << 4) | b2; + out[outIdx++] = (byte)((b << 4) | b2); inLen -= 2; } diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index f55452aee..a21d1b8c8 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -3784,7 +3784,7 @@ int ecc_test(void) /* test DSA sign hash */ for (i = 0; i < (int)sizeof(digest); i++) - digest[i] = i; + digest[i] = (byte)i; x = sizeof(sig); ret = ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &userA); diff --git a/cyassl/test.h b/cyassl/test.h index a59924823..e176e3b28 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -159,8 +159,8 @@ #define crlPemDir "./certs/crl" typedef struct tcp_ready { - int ready; /* predicate */ - int port; + word16 ready; /* predicate */ + word16 port; #if defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_mutex_t mutex; pthread_cond_t cond; @@ -558,7 +558,7 @@ static INLINE int tcp_select(SOCKET_T socketfd, int to_sec) #endif /* !CYASSL_MDK_ARM */ -static INLINE void tcp_listen(SOCKET_T* sockfd, int* port, int useAnyAddr, +static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr, int udp) { SOCKADDR_IN_T addr; @@ -620,7 +620,7 @@ static INLINE int udp_read_connect(SOCKET_T sockfd) } static INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, - int useAnyAddr, int port, func_args* args) + int useAnyAddr, word16 port, func_args* args) { SOCKADDR_IN_T addr; @@ -671,7 +671,7 @@ static INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, } static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, - func_args* args, int port, int useAnyAddr, + func_args* args, word16 port, int useAnyAddr, int udp) { SOCKADDR_IN_T client; diff --git a/examples/client/client.c b/examples/client/client.c index edc601e48..b2564d102 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -175,7 +175,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args) int input; int msgSz = (int)strlen(msg); - int port = yasslPort; + word16 port = yasslPort; char* host = (char*)yasslIP; char* domain = (char*)"www.yassl.com"; @@ -293,7 +293,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args) break; case 'p' : - port = atoi(myoptarg); + port = (word16)atoi(myoptarg); #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) if (port == 0) err_sys("port number cannot be 0"); diff --git a/examples/echoclient/echoclient.c b/examples/echoclient/echoclient.c index 903af3563..787d104ef 100644 --- a/examples/echoclient/echoclient.c +++ b/examples/echoclient/echoclient.c @@ -60,7 +60,7 @@ void echoclient_test(void* args) int sendSz; int argc = 0; char** argv = 0; - int port = yasslPort; + word16 port = yasslPort; ((func_args*)args)->return_code = -1; /* error state */ diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index 10bd3bab4..d612bfb76 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -48,7 +48,7 @@ #define SVR_COMMAND_SIZE 256 -static void SignalReady(void* args, int port) +static void SignalReady(void* args, word16 port) { #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && !defined(__MINGW32__) /* signal ready to tcp_accept */ @@ -76,7 +76,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args) int outCreated = 0; int shutDown = 0; int useAnyAddr = 0; - int port = yasslPort; + word16 port = yasslPort; int argc = ((func_args*)args)->argc; char** argv = ((func_args*)args)->argv; diff --git a/examples/server/server.c b/examples/server/server.c index 5c6920a00..435db8a23 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -153,7 +153,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) int version = SERVER_DEFAULT_VERSION; int doCliCertCheck = 1; int useAnyAddr = 0; - int port = yasslPort; + word16 port = yasslPort; int usePsk = 0; int doDTLS = 0; int useNtruKey = 0; @@ -230,7 +230,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) break; case 'p' : - port = atoi(myoptarg); + port = (word16)atoi(myoptarg); #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) if (port == 0) err_sys("port number cannot be 0"); diff --git a/src/internal.c b/src/internal.c index bba554558..0568337e3 100644 --- a/src/internal.c +++ b/src/internal.c @@ -231,7 +231,7 @@ static INLINE void c24to32(const word24 u24, word32* u32) /* convert opaque to 16 bit integer */ static INLINE void ato16(const byte* c, word16* u16) { - *u16 = (c[0] << 8) | (c[1]); + *u16 = (word16) ((c[0] << 8) | (c[1])); } @@ -4703,7 +4703,7 @@ static int DoAlert(CYASSL* ssl, byte* input, word32* inOutIdx, int* type) RECORD_HEADER_SZ, 2 + RECORD_HEADER_SZ, ssl->heap); #endif level = input[(*inOutIdx)++]; - code = (int)input[(*inOutIdx)++]; + code = input[(*inOutIdx)++]; ssl->alert_history.last_rx.code = code; ssl->alert_history.last_rx.level = level; *type = code; @@ -4904,7 +4904,7 @@ int ProcessReply(CYASSL* ssl) ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; b1 = ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; - ssl->curSize = ((b0 & 0x7f) << 8) | b1; + ssl->curSize = (word16)(((b0 & 0x7f) << 8) | b1); } else { ssl->options.processReply = getRecordLayerHeader; diff --git a/src/sniffer.c b/src/sniffer.c index 6779b4d8e..67a40a16c 100644 --- a/src/sniffer.c +++ b/src/sniffer.c @@ -1142,7 +1142,7 @@ static int ProcessSessionTicket(const byte* input, int* sslBytes, input += TICKET_HINT_LEN; /* skip over hint */ *sslBytes -= TICKET_HINT_LEN; - len = (input[0] << 8) | input[1]; + len = (word16)((input[0] << 8) | input[1]); input += LENGTH_SZ; *sslBytes -= LENGTH_SZ; @@ -1349,7 +1349,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, SetError(CLIENT_HELLO_INPUT_STR, error, session, FATAL_ERROR_STATE); return -1; } - len = (input[0] << 8) | input[1]; + len = (word16)((input[0] << 8) | input[1]); input += SUITE_LEN; *sslBytes -= SUITE_LEN; /* make sure can read suites + comp len */ @@ -1382,7 +1382,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, SetError(CLIENT_HELLO_INPUT_STR, error, session, FATAL_ERROR_STATE); return -1; } - len = (input[0] << 8) | input[1]; + len = (word16)((input[0] << 8) | input[1]); input += SUITE_LEN; *sslBytes -= SUITE_LEN; /* make sure can read through all extensions */ @@ -1400,7 +1400,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, input += EXT_TYPE_SZ; *sslBytes -= EXT_TYPE_SZ; - extLen = (input[0] << 8) | input[1]; + extLen = (word16)((input[0] << 8) | input[1]); input += LENGTH_SZ; *sslBytes -= LENGTH_SZ; @@ -1700,8 +1700,8 @@ static SnifferSession* CreateSession(IpInfo* ipInfo, TcpInfo* tcpInfo, InitSession(session); session->server = ipInfo->dst; session->client = ipInfo->src; - session->srvPort = tcpInfo->dstPort; - session->cliPort = tcpInfo->srcPort; + session->srvPort = (word16)tcpInfo->dstPort; + session->cliPort = (word16)tcpInfo->srcPort; session->cliSeqStart = tcpInfo->sequence; session->cliExpected = 1; /* relative */ session->lastUsed= time(NULL); @@ -1781,7 +1781,7 @@ static int DoOldHello(SnifferSession* session, const byte* sslFrame, } ret = ProcessOldClientHello(session->sslServer, input, &idx, *sslBytes, - *rhSize); + (word16)*rhSize); if (ret < 0 && ret != MATCH_SUITE_ERROR) { SetError(BAD_OLD_CLIENT_STR, error, session, FATAL_ERROR_STATE); return -1;