Merge pull request #3403 from elms/cppcheck/cleaup_fixes

Address some cppcheck issues
This commit is contained in:
tmael
2020-10-22 12:56:19 -07:00
committed by GitHub
4 changed files with 37 additions and 23 deletions

View File

@@ -571,22 +571,22 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
}
/* write bios */
if (bio && bio->type == WOLFSSL_BIO_BIO) {
if (bio->type == WOLFSSL_BIO_BIO) {
ret = wolfSSL_BIO_BIO_write(bio, data, len);
}
if (bio && bio->type == WOLFSSL_BIO_MEMORY) {
if (bio->type == WOLFSSL_BIO_MEMORY) {
ret = wolfSSL_BIO_MEMORY_write(bio, data, len);
}
#ifndef NO_FILESYSTEM
if (bio && bio->type == WOLFSSL_BIO_FILE) {
if (bio->type == WOLFSSL_BIO_FILE) {
ret = (int)XFWRITE(data, 1, len, (XFILE)bio->ptr);
}
#endif
#ifndef WOLFCRYPT_ONLY
if (bio && bio->type == WOLFSSL_BIO_SSL) {
if (bio->type == WOLFSSL_BIO_SSL) {
/* already got eof, again is error */
if (front->eof) {
ret = SSL_FATAL_ERROR;
@@ -596,7 +596,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
}
}
if (bio && bio->type == WOLFSSL_BIO_MD) {
if (bio->type == WOLFSSL_BIO_MD) {
if (bio->next != NULL) { /* data passing through MD BIO */
ret = wolfSSL_BIO_MD_write(bio, data, len);
}

View File

@@ -9985,7 +9985,13 @@ int DoVerifyCallback(WOLFSSL_CERT_MANAGER* cm, WOLFSSL* ssl, int ret,
ProcPeerCertArgs* args)
{
int verify_ok = 0, use_cb = 0;
void *heap = (ssl != NULL) ? ssl->heap : cm->heap;
void *heap;
if (cm == NULL) {
return BAD_FUNC_ARG;
}
heap = (ssl != NULL) ? ssl->heap : cm->heap;
/* Determine if verify was okay */
if (ret == 0) {
@@ -10190,7 +10196,7 @@ int DoVerifyCallback(WOLFSSL_CERT_MANAGER* cm, WOLFSSL* ssl, int ret,
}
#ifndef NO_WOLFSSL_CM_VERIFY
/* non-zero return code indicates failure override */
if ((cm != NULL) && (cm->verifyCallback != NULL)) {
if (cm->verifyCallback != NULL) {
store->userCtx = cm;
if (cm->verifyCallback(verify_ok, store)) {
if (ret != 0) {
@@ -11038,9 +11044,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
/* check if fatal error */
if (args->verifyErr) {
args->fatal = 1;
if (ret == 0) {
ret = args->lastErr;
}
ret = args->lastErr;
}
else {
args->fatal = 0;

View File

@@ -2269,13 +2269,15 @@ int mp_exptmod_base_2(mp_int * X, mp_int * P, mp_int * Y)
redux = fast_mp_montgomery_reduce;
} else
#endif
{
#ifdef BN_MP_MONTGOMERY_REDUCE_C
{
/* use slower baseline Montgomery method */
redux = mp_montgomery_reduce;
#else
return MP_VAL;
}
#endif
if (redux == NULL) {
return MP_VAL;
}
#ifdef WOLFSSL_SMALL_STACK

View File

@@ -117,16 +117,26 @@ static const sp_point p256_base __attribute__((aligned(128))) = {
static int sp_ecc_point_new_ex(void* heap, sp_point* sp, sp_point** p)
{
int ret = MP_OKAY;
(void)heap;
#if defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)
(void)sp;
*p = (sp_point*)XMALLOC(sizeof(sp_point), heap, DYNAMIC_TYPE_ECC);
#else
*p = sp;
#endif
if (p == NULL) {
ret = MEMORY_E;
} else {
#if defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)
(void)sp;
*p = (sp_point*)XMALLOC(sizeof(sp_point), heap, DYNAMIC_TYPE_ECC);
if (*p == NULL) {
ret = MEMORY_E;
}
#else
(void)heap;
if (sp == NULL) {
ret = MEMORY_E;
} else {
*p = sp;
}
#endif
}
return ret;
}
@@ -4533,14 +4543,12 @@ void wc_ecc_fp_free(void)
AEEResult wolfSSL_open(const char *uri, remote_handle64 *handle)
{
void *tptr;
/* can be any value or ignored, rpc layer doesn't care
* also ok
* *handle = 0;
* *handle = 0xdeadc0de;
*/
tptr = (void *)malloc(1);
*handle = (remote_handle64)tptr;
*handle = (remote_handle64)malloc(1);
return 0;
}