Skip to content

Commit 2273178

Browse files
committed
Move deref to after non-null assert
Asserting afterwards triggers a GCC static analysis error: source/sigv4.c:2413:5: warning: check of ‘pHmacContext_22(D)’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] 2413 | assert( pHmacContext != NULL ); | ^ ‘hmacIntermediate’: events 1-2 | | 2411 | const SigV4CryptoInterface_t * pCryptoInterface = pHmacContext->pCryptoInterface; | | ^ | | | | | (1) pointer ‘pHmacContext_22(D)’ is dereferenced here | 2412 | | 2413 | assert( pHmacContext != NULL ); | | ~ | | | | | (2) pointer ‘pHmacContext_22(D)’ is checked for NULL here but it was already dereferenced at (1) |
1 parent 5b8dbdf commit 2273178

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

source/sigv4.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ static int32_t hmacIntermediate( HmacContext_t * pHmacContext,
24082408
{
24092409
int32_t returnStatus = 0;
24102410
size_t i = 0U;
2411-
const SigV4CryptoInterface_t * pCryptoInterface = pHmacContext->pCryptoInterface;
2411+
const SigV4CryptoInterface_t * pCryptoInterface;
24122412

24132413
assert( pHmacContext != NULL );
24142414
assert( dataLen > 0U );
@@ -2417,7 +2417,9 @@ static int32_t hmacIntermediate( HmacContext_t * pHmacContext,
24172417
assert( pHmacContext->pCryptoInterface->hashInit != NULL );
24182418
assert( pHmacContext->pCryptoInterface->hashUpdate != NULL );
24192419
assert( pHmacContext->pCryptoInterface->hashFinal != NULL );
2420-
assert( pHmacContext->keyLen == pCryptoInterface->hashBlockLen );
2420+
assert( pHmacContext->keyLen == pHmacContext->pCryptoInterface->hashBlockLen );
2421+
2422+
pCryptoInterface = pHmacContext->pCryptoInterface;
24212423

24222424
/* Derive the inner HMAC key by XORing the key with inner pad byte. */
24232425
for( i = 0U; i < pCryptoInterface->hashBlockLen; i++ )

0 commit comments

Comments
 (0)