Skip to content

Commit

Permalink
Merge pull request #6259 from SparkiDev/cppcheck_fixes_9
Browse files Browse the repository at this point in the history
cppcheck fixes
  • Loading branch information
dgarske authored Apr 3, 2023
2 parents b6ab7a9 + 8851065 commit b1e4d49
Show file tree
Hide file tree
Showing 41 changed files with 394 additions and 420 deletions.
2 changes: 1 addition & 1 deletion IDE/Espressif/ESP-IDF/test/test_wolfssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ TEST_CASE("wolfssl aes sha256 rsa multi-thread test ", "[wolfssl]")
exit_loop = true;

/* wait until rsa test finishes */
while(rsa_elapsedTime<=0){ vTaskDelay(1); }
while(rsa_elapsedTime==0){ vTaskDelay(1); }

ESP_LOGI(TAG, "Waiting another %llu s. rsa test would take more time to finish.",
(rsa_elapsedTime+3000)/portTICK_PERIOD_MS);
Expand Down
4 changes: 1 addition & 3 deletions examples/benchmark/tls_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,12 +1269,10 @@ static int SocketWaitClient(info_t* info)
int connd;
struct sockaddr_in clientAddr;
socklen_t size = sizeof(clientAddr);
#ifdef WOLFSSL_DTLS
char msg[64];
#endif

#ifdef WOLFSSL_DTLS
if (info->doDTLS) {
char msg[64];
#ifdef HAVE_PTHREAD
if (!info->clientOrserverOnly) {
PTHREAD_CHECK_RET(pthread_mutex_lock(&info->dtls_mutex));
Expand Down
10 changes: 4 additions & 6 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
err_sys("Client buffer malloc failed");
}
doExit:
if (tx_buffer) XFREE(tx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (rx_buffer) XFREE(rx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(tx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(rx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
else {
err_sys("wolfSSL_connect failed");
Expand Down Expand Up @@ -953,7 +953,6 @@ static int ClientWrite(WOLFSSL* ssl, const char* msg, int msgSz, const char* str
int exitWithRet)
{
int ret, err;
char buffer[WOLFSSL_MAX_ERROR_SZ];

do {
err = 0; /* reset error */
Expand All @@ -974,6 +973,7 @@ static int ClientWrite(WOLFSSL* ssl, const char* msg, int msgSz, const char* str
#endif
);
if (ret != msgSz) {
char buffer[WOLFSSL_MAX_ERROR_SZ];
fprintf(stderr, "SSL_write%s msg error %d, %s\n", str, err,
wolfSSL_ERR_error_string(err, buffer));
if (!exitWithRet) {
Expand Down Expand Up @@ -4311,9 +4311,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)

#if !defined(NO_SESSION_CACHE) && (defined(OPENSSL_EXTRA) || \
defined(HAVE_EXT_CACHE))
if (flatSession) {
XFREE(flatSession, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(flatSession, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
wolfSSL_SESSION_free(session);
session = NULL;
Expand Down
3 changes: 2 additions & 1 deletion examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
CYASSL* ssl = NULL;
CYASSL* write_ssl = NULL; /* may have separate w/ HAVE_WRITE_DUP */
char command[SVR_COMMAND_SIZE+1];
int echoSz = 0;
int clientfd;
int firstRead = 1;
int gotFirstG = 0;
Expand Down Expand Up @@ -374,6 +373,8 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
#endif

while (1) {
int echoSz;

do {
err = 0; /* reset error */
ret = CyaSSL_read(ssl, command, sizeof(command)-1);
Expand Down
22 changes: 12 additions & 10 deletions examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ static int TestEmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
WOLFSSL_TEST_DTLS_CTX* dtlsCtx = (WOLFSSL_TEST_DTLS_CTX*)ctx;
int sd = dtlsCtx->wfd;
int sent;
int err;

(void)ssl;

Expand All @@ -291,7 +290,7 @@ static int TestEmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
sent = TranslateReturnCode(sent, sd);

if (sent < 0) {
err = wolfSSL_LastError();
int err = wolfSSL_LastError();
WOLFSSL_MSG("Embed Send To error");

if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
Expand Down Expand Up @@ -337,8 +336,6 @@ static int NonBlockingSSL_Accept(SSL* ssl)
|| error == WC_PENDING_E
#endif
)) {
int currTimeout = 1;

if (error == WOLFSSL_ERROR_WANT_READ) {
/* printf("... server would read block\n"); */
}
Expand All @@ -354,6 +351,8 @@ static int NonBlockingSSL_Accept(SSL* ssl)
else
#endif
{
int currTimeout = 1;

if (error == WOLFSSL_ERROR_WANT_WRITE)
{
select_ret = tcp_select_tx(sockfd, currTimeout);
Expand Down Expand Up @@ -408,7 +407,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
{
int ret = 0, err;
double start = 0, rx_time = 0, tx_time = 0;
int select_ret, len, rx_pos;
int len, rx_pos;
size_t xfer_bytes = 0;
char* buffer;

Expand All @@ -420,7 +419,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
while ((echoData && throughput == 0) ||
(!echoData && xfer_bytes < throughput))
{
select_ret = tcp_select(clientfd, 1); /* Timeout=1 second */
int select_ret = tcp_select(clientfd, 1); /* Timeout=1 second */
if (select_ret == TEST_RECV_READY) {

if (throughput)
Expand Down Expand Up @@ -611,7 +610,6 @@ static void ServerRead(WOLFSSL* ssl, char* input, int inputLen)
static void ServerWrite(WOLFSSL* ssl, const char* output, int outputLen)
{
int ret, err;
char buffer[WOLFSSL_MAX_ERROR_SZ];
int len;

#ifdef OPENSSL_ALL
Expand Down Expand Up @@ -642,6 +640,7 @@ static void ServerWrite(WOLFSSL* ssl, const char* output, int outputLen)
}
} while (err == WC_PENDING_E || err == WOLFSSL_ERROR_WANT_WRITE);
if (ret != outputLen) {
char buffer[WOLFSSL_MAX_ERROR_SZ];
fprintf(stderr, "SSL_write msg error %d, %s\n", err,
ERR_error_string(err, buffer));
err_sys_ex(runWithErrors, "SSL_write failed");
Expand Down Expand Up @@ -2193,10 +2192,12 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
case 262: {
/* Note: this requires TSL1.3 (version >= 4) */
#ifdef HAVE_ECC
int idx = 0; /* ecc curve index */
int j = 0; /* our group index */
#endif
if (NULL == myoptarg) {
#ifdef HAVE_ECC
int idx = 0; /* ecc curve index */
#endif
Usage();
if (lng_index == 1) {
/* TODO: Need Japanese translation */
Expand Down Expand Up @@ -3167,10 +3168,11 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
#if defined(WOLFSSL_DTLS) && defined(USE_WOLFSSL_IO)
if (doDTLS && dtlsUDP) {
byte b[1500];
int n;
int isClientHello = 0;

while (!isClientHello) {
int n;

client_len = sizeof client_addr;

/* For DTLS, peek at the next datagram so we can get the
Expand Down Expand Up @@ -3411,7 +3413,6 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
#if defined(OPENSSL_EXTRA) || defined(HAVE_SECRET_CALLBACK)
{
byte* rnd = NULL;
byte* pt;
size_t size;

/* get size of buffer then print */
Expand All @@ -3438,6 +3439,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
}

if (rnd) {
byte* pt;
printf("Server Random : ");
for (pt = rnd; pt < rnd + size; pt++) printf("%02X", *pt);
printf("\n");
Expand Down
10 changes: 3 additions & 7 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2057,11 +2057,10 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
WOLFSSL_BIO *wolfSSL_BIO_new_connect(const char *str)
{
WOLFSSL_BIO *bio;
const char* port;
WOLFSSL_ENTER("wolfSSL_BIO_new_connect");
bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket());
if (bio) {
port = XSTRSTR(str, ":");
const char* port = XSTRSTR(str, ":");

if (port != NULL)
bio->port = (word16)XATOI(port + 1);
Expand Down Expand Up @@ -2261,8 +2260,6 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)

void wolfSSL_BIO_ssl_shutdown(WOLFSSL_BIO* b)
{
int rc;

WOLFSSL_ENTER("wolfSSL_BIO_ssl_shutdown");

if (b == NULL) {
Expand All @@ -2279,7 +2276,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
}

if (b->ptr != NULL) {
rc = wolfSSL_shutdown((WOLFSSL*)b->ptr);
int rc = wolfSSL_shutdown((WOLFSSL*)b->ptr);
if (rc == SSL_SHUTDOWN_NOT_DONE) {
/* In this case, call again to give us a chance to read the
* close notify alert from the other end. */
Expand Down Expand Up @@ -2386,7 +2383,6 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)

long wolfSSL_BIO_set_conn_hostname(WOLFSSL_BIO* b, char* name)
{
size_t currLen = 0;
size_t newLen = 0;

WOLFSSL_ENTER("wolfSSL_BIO_set_conn_hostname");
Expand Down Expand Up @@ -2414,7 +2410,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
}
}
else {
currLen = XSTRLEN(b->ip);
size_t currLen = XSTRLEN(b->ip);
if (currLen != newLen) {
b->ip = (char*)XREALLOC(b->ip, newLen + 1, b->heap,
DYNAMIC_TYPE_OPENSSL);
Expand Down
5 changes: 2 additions & 3 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ long wolfSSL_TXT_DB_write(WOLFSSL_BIO *out, WOLFSSL_TXT_DB *db)
long totalLen = 0;
char buf[512]; /* Should be more than enough for a single row */
char* bufEnd = buf + sizeof(buf);
int sz;
int i;

WOLFSSL_ENTER("wolfSSL_TXT_DB_write");
Expand All @@ -172,6 +171,7 @@ long wolfSSL_TXT_DB_write(WOLFSSL_BIO *out, WOLFSSL_TXT_DB *db)
while (data) {
char** fields = (char**)data->data.string;
char* idx = buf;
int sz;

if (!fields) {
WOLFSSL_MSG("Missing row");
Expand Down Expand Up @@ -1499,10 +1499,9 @@ static const conf_cmd_tbl* wolfssl_conf_find_cmd(WOLFSSL_CONF_CTX* cctx,
const char* cmd)
{
size_t i = 0;
size_t cmdlen = 0;

if (cctx->flags & WOLFSSL_CONF_FLAG_CMDLINE) {
cmdlen = XSTRLEN(cmd);
size_t cmdlen = XSTRLEN(cmd);

if (cmdlen < 2) {
WOLFSSL_MSG("bad cmdline command");
Expand Down
Loading

0 comments on commit b1e4d49

Please sign in to comment.