scan-build fixes: back out all "#ifndef __clang_analyzer__" wrappers added to suppress false and frivolous positives from alpha.deadcode.UnreachableCode, and rename new macro WC_UNUSED to WC_MAYBE_UNUSED to make its meaning more precisely apparent. build is still clean with -Wunreachable-code-break -Wunreachable-code-return under scan-build-13.

This commit is contained in:
Daniel Pouzzner
2021-10-15 17:20:14 -05:00
parent f621a93081
commit 816527e826
10 changed files with 10 additions and 47 deletions

View File

@@ -28624,12 +28624,10 @@ int wolfSSL_X509_PUBKEY_set(WOLFSSL_X509_PUBKEY **x, WOLFSSL_EVP_PKEY *key)
goto error; goto error;
} }
#ifndef __clang_analyzer__
if (!wolfSSL_EVP_PKEY_up_ref(key)) { if (!wolfSSL_EVP_PKEY_up_ref(key)) {
WOLFSSL_MSG("Failed to up key reference"); WOLFSSL_MSG("Failed to up key reference");
goto error; goto error;
} }
#endif
pk->pkey = key; pk->pkey = key;
wolfSSL_X509_PUBKEY_free(*x); wolfSSL_X509_PUBKEY_free(*x);
@@ -31536,12 +31534,10 @@ WOLFSSL_ASN1_INTEGER* wolfSSL_BN_to_ASN1_INTEGER(const WOLFSSL_BIGNUM *bn, WOLFS
a = ai; a = ai;
} }
if (a) { if (a) {
#ifndef __clang_analyzer__
if (wolfSSL_BN_is_negative(bn) && !wolfSSL_BN_is_zero(bn)) { if (wolfSSL_BN_is_negative(bn) && !wolfSSL_BN_is_zero(bn)) {
a->type |= V_ASN1_NEG_INTEGER; a->type |= V_ASN1_NEG_INTEGER;
a->negative = 1; a->negative = 1;
} }
#endif
len = wolfSSL_BN_num_bytes(bn); len = wolfSSL_BN_num_bytes(bn);
if (len == 0) if (len == 0)
@@ -31777,13 +31773,11 @@ int wolfSSL_ASN1_item_i2d(const void *src, byte **dest,
if (dest && !*dest) { if (dest && !*dest) {
*dest = buf; *dest = buf;
} }
#ifndef __clang_analyzer__
else if (dest && *dest && buf) { else if (dest && *dest && buf) {
/* *dest length is not checked because the user is responsible /* *dest length is not checked because the user is responsible
* for providing a long enough buffer */ * for providing a long enough buffer */
XMEMCPY(*dest, buf, len); XMEMCPY(*dest, buf, len);
} }
#endif
WOLFSSL_LEAVE("wolfSSL_ASN1_item_i2d", len); WOLFSSL_LEAVE("wolfSSL_ASN1_item_i2d", len);
return len; return len;
@@ -54534,13 +54528,11 @@ void wolfSSL_X509V3_set_ctx(WOLFSSL_X509V3_CTX* ctx, WOLFSSL_X509* issuer,
if (!ctx || !ctx->x509) if (!ctx || !ctx->x509)
return; return;
#ifndef __clang_analyzer__
if (!ctx->x509) { if (!ctx->x509) {
ctx->x509 = wolfSSL_X509_new(); ctx->x509 = wolfSSL_X509_new();
if (!ctx->x509) if (!ctx->x509)
return; return;
} }
#endif
/* Set parameters in ctx as long as ret == WOLFSSL_SUCCESS */ /* Set parameters in ctx as long as ret == WOLFSSL_SUCCESS */
if (issuer) if (issuer)
@@ -54622,7 +54614,7 @@ void wolfSSL_X509_REQ_free(WOLFSSL_X509* req)
int wolfSSL_X509_REQ_sign(WOLFSSL_X509 *req, WOLFSSL_EVP_PKEY *pkey, int wolfSSL_X509_REQ_sign(WOLFSSL_X509 *req, WOLFSSL_EVP_PKEY *pkey,
const WOLFSSL_EVP_MD *md) const WOLFSSL_EVP_MD *md)
{ {
WC_UNUSED int ret; WC_MAYBE_UNUSED int ret;
byte der[2048]; byte der[2048];
int derSz = sizeof(der); int derSz = sizeof(der);
@@ -58063,10 +58055,8 @@ void *wolfSSL_BIO_get_ex_data(WOLFSSL_BIO *bio, int idx)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
#ifndef NO_FILESYSTEM #ifndef NO_FILESYSTEM
#ifdef __clang__ PRAGMA_CLANG_DIAG_PUSH
#pragma clang diagnostic push PRAGMA_CLANG("clang diagnostic ignored \"-Wformat-nonliteral\"")
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
#endif #endif
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
@@ -58149,8 +58139,8 @@ int wolfSSL_BIO_printf(WOLFSSL_BIO* bio, const char* format, ...)
} }
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
#if !defined(NO_FILESYSTEM) && defined(__clang__) #ifndef NO_FILESYSTEM
#pragma clang diagnostic pop PRAGMA_CLANG_DIAG_POP
#endif #endif
#undef LINE_LEN #undef LINE_LEN

View File

@@ -10302,12 +10302,10 @@ int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isServer)
extension = TLSX_Find(ssl->extensions, TLSX_KEY_SHARE); extension = TLSX_Find(ssl->extensions, TLSX_KEY_SHARE);
if (extension == NULL) { if (extension == NULL) {
#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK) #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
#ifndef __clang_analyzer__
if (ssl->options.resuming && ssl->session.namedGroup != 0) if (ssl->options.resuming && ssl->session.namedGroup != 0)
namedGroup = ssl->session.namedGroup; namedGroup = ssl->session.namedGroup;
else else
#endif #endif
#endif
PRAGMA_CLANG_DIAG_PUSH PRAGMA_CLANG_DIAG_PUSH
PRAGMA_CLANG("clang diagnostic ignored \"-Wunreachable-code-return\"") PRAGMA_CLANG("clang diagnostic ignored \"-Wunreachable-code-return\"")
if (PREFERRED_GROUP_SZ == 0) { if (PREFERRED_GROUP_SZ == 0) {

View File

@@ -29,8 +29,6 @@
| Includes | Includes
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
#ifndef __clang_analyzer__
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
@@ -39513,7 +39511,7 @@ static int test_wolfSSL_EVP_Cipher_extra(void)
int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL}; int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
int test_drive_len[100]; int test_drive_len[100];
WC_UNUSED int drive_len; WC_MAYBE_UNUSED int drive_len;
int ret = 0; int ret = 0;
EVP_CIPHER_CTX *evp = NULL; EVP_CIPHER_CTX *evp = NULL;
@@ -51085,5 +51083,3 @@ void ApiTest(void)
printf(" End API Tests\n"); printf(" End API Tests\n");
} }
#endif /* !__clang_analyzer__ */

View File

@@ -11141,11 +11141,9 @@ int wc_AesKeyWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
return MEMORY_E; return MEMORY_E;
#endif #endif
#ifndef __clang_analyzer__
ret = wc_AesInit(aes, NULL, INVALID_DEVID); ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) if (ret != 0)
goto out; goto out;
#endif
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION); ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION);
if (ret != 0) { if (ret != 0) {
@@ -11256,11 +11254,9 @@ int wc_AesKeyUnWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
#endif #endif
#ifndef __clang_analyzer__
ret = wc_AesInit(aes, NULL, INVALID_DEVID); ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) if (ret != 0)
goto out; goto out;
#endif
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_DECRYPTION); ret = wc_AesSetKey(aes, key, keySz, NULL, AES_DECRYPTION);
if (ret != 0) { if (ret != 0) {
@@ -11313,14 +11309,12 @@ int wc_AesXtsSetKey(XtsAes* aes, const byte* key, word32 len, int dir,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifndef __clang_analyzer__
if ((ret = wc_AesInit(&aes->tweak, heap, devId)) != 0) { if ((ret = wc_AesInit(&aes->tweak, heap, devId)) != 0) {
return ret; return ret;
} }
if ((ret = wc_AesInit(&aes->aes, heap, devId)) != 0) { if ((ret = wc_AesInit(&aes->aes, heap, devId)) != 0) {
return ret; return ret;
} }
#endif
keySz = len/2; keySz = len/2;
if (keySz != 16 && keySz != 32) { if (keySz != 16 && keySz != 32) {

View File

@@ -300,10 +300,8 @@ int wc_XChacha_SetKey(ChaCha *ctx,
XMEMSET(iv, 0, 4); XMEMSET(iv, 0, 4);
XMEMCPY(iv + 4, nonce + 16, 8); XMEMCPY(iv + 4, nonce + 16, 8);
#ifndef __clang_analyzer__
if ((ret = wc_Chacha_SetIV(ctx, iv, counter)) < 0) if ((ret = wc_Chacha_SetIV(ctx, iv, counter)) < 0)
return ret; return ret;
#endif
ForceZero(k, sizeof k); ForceZero(k, sizeof k);
ForceZero(iv, sizeof iv); ForceZero(iv, sizeof iv);

View File

@@ -2280,7 +2280,6 @@ WC_PKCS12* wc_PKCS12_create(char* pass, word32 passSz, char* name,
return NULL; return NULL;
} }
#ifndef __clang_analyzer__
if ((ret = wc_PKCS12_SetHeap(pkcs12, heap)) != 0) { if ((ret = wc_PKCS12_SetHeap(pkcs12, heap)) != 0) {
wc_PKCS12_free(pkcs12); wc_PKCS12_free(pkcs12);
wc_FreeRng(&rng); wc_FreeRng(&rng);
@@ -2288,7 +2287,6 @@ WC_PKCS12* wc_PKCS12_create(char* pass, word32 passSz, char* name,
(void)ret; (void)ret;
return NULL; return NULL;
} }
#endif
if (iter <= 0) { if (iter <= 0) {
iter = WC_PKCS12_ITT_DEFAULT; iter = WC_PKCS12_ITT_DEFAULT;

View File

@@ -770,12 +770,10 @@ PKCS7* wc_PKCS7_New(void* heap, int devId)
if (wc_PKCS7_Init(pkcs7, heap, devId) == 0) { if (wc_PKCS7_Init(pkcs7, heap, devId) == 0) {
pkcs7->isDynamic = 1; pkcs7->isDynamic = 1;
} }
#ifndef __clang_analyzer__
else { else {
XFREE(pkcs7, heap, DYNAMIC_TYPE_PKCS7); XFREE(pkcs7, heap, DYNAMIC_TYPE_PKCS7);
pkcs7 = NULL; pkcs7 = NULL;
} }
#endif
} }
return pkcs7; return pkcs7;
} }
@@ -1532,9 +1530,6 @@ static int EncodeAttributes(EncodedAttrib* ea, int eaSz,
int maxSz = min(eaSz, attribsSz); int maxSz = min(eaSz, attribsSz);
int allAttribsSz = 0; int allAttribsSz = 0;
#ifdef __clang_analyzer__
assert(maxSz > 0);
#endif
for (i = 0; i < maxSz; i++) for (i = 0; i < maxSz; i++)
{ {
int attribSz = 0; int attribSz = 0;

View File

@@ -620,14 +620,12 @@ static int wc_SrpSetKey(Srp* srp, byte* secret, word32 size)
if (!r) r = SrpHashUpdate(&hash, counter, 4); if (!r) r = SrpHashUpdate(&hash, counter, 4);
if (!r) { if (!r) {
#ifndef __clang_analyzer__
if (j + digestSz > srp->keySz) { if (j + digestSz > srp->keySz) {
r = SrpHashFinal(&hash, digest); r = SrpHashFinal(&hash, digest);
XMEMCPY(srp->key + j, digest, srp->keySz - j); XMEMCPY(srp->key + j, digest, srp->keySz - j);
j = srp->keySz; j = srp->keySz;
} }
else else
#endif
{ {
r = SrpHashFinal(&hash, srp->key + j); r = SrpHashFinal(&hash, srp->key + j);
j += digestSz; j += digestSz;

View File

@@ -19045,11 +19045,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void)
return -8672; return -8672;
if(outlen != 16) if(outlen != 16)
return -8673; return -8673;
#ifndef __clang_analyzer__
total += outlen; total += outlen;
if(total != 32) if(total != 32)
return -8674; return -8674;
#endif
total = 0; total = 0;
EVP_CIPHER_CTX_init(de); EVP_CIPHER_CTX_init(de);
@@ -19109,11 +19107,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void)
return -8690; return -8690;
if(outlen != 16) if(outlen != 16)
return -8691; return -8691;
#ifndef __clang_analyzer__
total += outlen; total += outlen;
if(total != 32) if(total != 32)
return 3438; return 3438;
#endif
total = 0; total = 0;
EVP_CIPHER_CTX_init(de); EVP_CIPHER_CTX_init(de);

View File

@@ -330,13 +330,13 @@ decouple library dependencies with standard string, memory and so on.
#endif #endif
#endif /* WARN_UNUSED_RESULT */ #endif /* WARN_UNUSED_RESULT */
#ifndef WC_UNUSED #ifndef WC_MAYBE_UNUSED
#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) #if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
#define WC_UNUSED __attribute__((unused)) #define WC_MAYBE_UNUSED __attribute__((unused))
#else #else
#define WC_UNUSED #define WC_MAYBE_UNUSED
#endif #endif
#endif /* WC_UNUSED */ #endif /* WC_MAYBE_UNUSED */
/* Micrium will use Visual Studio for compilation but not the Win32 API */ /* Micrium will use Visual Studio for compilation but not the Win32 API */
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \ #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \