wolfcrypt/src/wc_port.c: fixes for cppcheck complaints: uninitvar nullPointer

This commit is contained in:
Daniel Pouzzner
2022-01-08 00:33:33 -06:00
parent 8aa1100508
commit 70ab36f81c

View File

@@ -130,7 +130,7 @@ int wolfCrypt_Init(void)
time_t seed = time(NULL); time_t seed = time(NULL);
srand((word32)seed); srand((word32)seed);
rngMallocFail = rand() % 2000; /* max 2000 */ rngMallocFail = rand() % 2000; /* max 2000 */
printf("\n--- RNG MALLOC FAIL AT %d---\n", rngMallocFail); printf("\n--- RNG MALLOC FAIL AT %u ---\n", rngMallocFail);
wolfSSL_SetMemFailCount(rngMallocFail); wolfSSL_SetMemFailCount(rngMallocFail);
} }
#endif #endif
@@ -1649,7 +1649,7 @@ int wolfSSL_CryptHwMutexUnLock(void)
void *newp = NULL; void *newp = NULL;
if(p) { if(p) {
ercd = get_mpl(ID_wolfssl_MPOOL, sz, (VP)&newp); ercd = get_mpl(ID_wolfssl_MPOOL, sz, (VP)&newp);
if (ercd == E_OK) { if ((ercd == E_OK) && (newp != NULL)) {
XMEMCPY(newp, p, sz); XMEMCPY(newp, p, sz);
ercd = rel_mpl(ID_wolfssl_MPOOL, (VP)p); ercd = rel_mpl(ID_wolfssl_MPOOL, (VP)p);
if (ercd == E_OK) { if (ercd == E_OK) {
@@ -1743,7 +1743,7 @@ int wolfSSL_CryptHwMutexUnLock(void)
void *newp = NULL; void *newp = NULL;
if (p) { if (p) {
ercd = tk_get_mpl(ID_wolfssl_MPOOL, sz, (VP)&newp, TMO_FEVR); ercd = tk_get_mpl(ID_wolfssl_MPOOL, sz, (VP)&newp, TMO_FEVR);
if (ercd == E_OK) { if ((ercd == E_OK) && (newp != NULL)) {
XMEMCPY(newp, p, sz); XMEMCPY(newp, p, sz);
ercd = tk_rel_mpl(ID_wolfssl_MPOOL, (VP)p); ercd = tk_rel_mpl(ID_wolfssl_MPOOL, (VP)p);
if (ercd == E_OK) { if (ercd == E_OK) {
@@ -2150,10 +2150,7 @@ time_t windows_time(time_t* timer)
SYSTEMTIME sysTime; SYSTEMTIME sysTime;
FILETIME fTime; FILETIME fTime;
ULARGE_INTEGER intTime; ULARGE_INTEGER intTime;
time_t localTime;
if (timer == NULL)
timer = &localTime;
GetSystemTime(&sysTime); GetSystemTime(&sysTime);
SystemTimeToFileTime(&sysTime, &fTime); SystemTimeToFileTime(&sysTime, &fTime);
@@ -2163,9 +2160,11 @@ time_t windows_time(time_t* timer)
intTime.QuadPart -= 0x19db1ded53e8000; intTime.QuadPart -= 0x19db1ded53e8000;
/* to secs */ /* to secs */
intTime.QuadPart /= 10000000; intTime.QuadPart /= 10000000;
*timer = (time_t)intTime.QuadPart;
return *timer; if (timer != NULL)
*timer = (time_t)intTime.QuadPart;
return (time_t)intTime.QuadPart;
} }
#endif /* _WIN32_WCE */ #endif /* _WIN32_WCE */
@@ -2275,19 +2274,17 @@ time_t pic32_time(time_t* timer)
#else #else
word32 sec = 0; word32 sec = 0;
#endif #endif
time_t localTime;
if (timer == NULL)
timer = &localTime;
#ifdef MICROCHIP_MPLAB_HARMONY #ifdef MICROCHIP_MPLAB_HARMONY
sec = TCPIP_SNTP_UTCSecondsGet(); sec = TCPIP_SNTP_UTCSecondsGet();
#else #else
sec = SNTPGetUTCSeconds(); sec = SNTPGetUTCSeconds();
#endif #endif
*timer = (time_t) sec;
return *timer; if (timer != NULL)
*timer = (time_t)sec;
return (time_t)sec;
} }
#endif /* MICROCHIP_TCPIP || MICROCHIP_TCPIP_V5 */ #endif /* MICROCHIP_TCPIP || MICROCHIP_TCPIP_V5 */
@@ -2331,16 +2328,14 @@ time_t micrium_time(time_t* timer)
time_t mqx_time(time_t* timer) time_t mqx_time(time_t* timer)
{ {
time_t localTime;
TIME_STRUCT time_s; TIME_STRUCT time_s;
if (timer == NULL)
timer = &localTime;
_time_get(&time_s); _time_get(&time_s);
*timer = (time_t) time_s.SECONDS;
return *timer; if (timer != NULL)
*timer = (time_t)time_s.SECONDS;
return (time_t)time_s.SECONDS;
} }
#endif /* FREESCALE_MQX || FREESCALE_KSDK_MQX */ #endif /* FREESCALE_MQX || FREESCALE_KSDK_MQX */