From 3bcdef19721086d408faab50be32082c76b46c2b Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 3 Jun 2022 09:37:17 -0600 Subject: [PATCH 1/2] Fix various warnings and an uninitialized XFILE --- examples/client/client.c | 10 +++++++--- src/wolfio.c | 4 ++-- wolfcrypt/src/asn.c | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index 228ffcddc..52be85581 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -544,7 +544,8 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port, int version, int earlyData) { /* time passed in number of connects give average */ - int times = benchmark, skip = times * 0.1; + int times = benchmark; + double skip = (double) times * 0.1; int loops = resumeSession ? 2 : 1; int i = 0, err, ret; #ifndef NO_SESSION_CACHE @@ -569,13 +570,16 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port, #ifndef NO_SESSION_CACHE int benchResume = resumeSession && loops == 0; #endif - double start = current_time(1), avg; + double start = current_time(1), avg, check; for (i = 0; i < times; i++) { SOCKET_T sockfd; WOLFSSL* ssl; - if (i == skip) + /* cannot compare doubles with == or != instead subtract and if + * result is 0 then they were equal */ + check = (double)i - skip; + if (check > -1.0 && check < 1.0) start = current_time(1); ssl = wolfSSL_new(ctx); diff --git a/src/wolfio.c b/src/wolfio.c index deb2ebcd3..6685cb8e6 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -335,7 +335,7 @@ static int sockAddrEqual( if (a->ss_family == AF_INET) { - if (aLen < sizeof(SOCKADDR_IN)) + if (aLen < (XSOCKLENT)sizeof(SOCKADDR_IN)) return 0; if (((SOCKADDR_IN*)a)->sin_port != ((SOCKADDR_IN*)b)->sin_port) @@ -352,7 +352,7 @@ static int sockAddrEqual( if (a->ss_family == AF_INET6) { SOCKADDR_IN6 *a6, *b6; - if (aLen < sizeof(SOCKADDR_IN6)) + if (aLen < (XSOCKLENT)sizeof(SOCKADDR_IN6)) return 0; a6 = (SOCKADDR_IN6*)a; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index c2545dd00..6848ebb52 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -20654,7 +20654,7 @@ int wc_PemPubKeyToDer_ex(const char* fileName, DerBuffer** der) int dynamic = 0; int ret = 0; long sz = 0; - XFILE file; + XFILE file = NULL; WOLFSSL_ENTER("wc_PemPubKeyToDer"); From 96d5814bfe8a71ce3477837271c9e64a733d616d Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 3 Jun 2022 11:06:46 -0600 Subject: [PATCH 2/2] Implement peer review feedback --- examples/client/client.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index 52be85581..bfd152c1c 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -544,8 +544,7 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port, int version, int earlyData) { /* time passed in number of connects give average */ - int times = benchmark; - double skip = (double) times * 0.1; + int times = benchmark, skip = (int)((double)times * 0.1); int loops = resumeSession ? 2 : 1; int i = 0, err, ret; #ifndef NO_SESSION_CACHE @@ -570,16 +569,13 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port, #ifndef NO_SESSION_CACHE int benchResume = resumeSession && loops == 0; #endif - double start = current_time(1), avg, check; + double start = current_time(1), avg; for (i = 0; i < times; i++) { SOCKET_T sockfd; WOLFSSL* ssl; - /* cannot compare doubles with == or != instead subtract and if - * result is 0 then they were equal */ - check = (double)i - skip; - if (check > -1.0 && check < 1.0) + if (i == skip) start = current_time(1); ssl = wolfSSL_new(ctx);