Clean GCC 10 Analyzer warnings

This commit is contained in:
Jeffrey Walton 2020-05-10 01:25:39 -04:00
parent 7a8e241c7c
commit 680956e134
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
3 changed files with 6 additions and 4 deletions

View File

@ -25,7 +25,7 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con
if (keylength <= blockSize)
{
// hmac.cpp:26:9: runtime error: null pointer passed as argument 2
if (userKey && keylength)
if (AccessIpad() && userKey && keylength)
memcpy(AccessIpad(), userKey, keylength);
}
else

3
misc.h
View File

@ -524,7 +524,8 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou
# pragma warning(disable: 6386)
# endif
#endif
memcpy(dest, src, count);
if (src && dest)
memcpy(dest, src, count);
#if CRYPTOPP_MSC_VERSION
# pragma warning(pop)
#endif

View File

@ -748,7 +748,8 @@ public:
SecBlock(const SecBlock<T, A> &t)
: m_mark(t.m_mark), m_size(t.m_size), m_ptr(m_alloc.allocate(t.m_size, NULLPTR)) {
CRYPTOPP_ASSERT((!t.m_ptr && !m_size) || (t.m_ptr && m_size));
if (t.m_ptr) {memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));}
if (m_ptr && t.m_ptr)
memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
}
/// \brief Construct a SecBlock from an array of elements.
@ -764,7 +765,7 @@ public:
CRYPTOPP_ASSERT((!m_ptr && !m_size) || (m_ptr && m_size));
if (ptr && m_ptr)
memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T));
else if (m_size)
else if (m_ptr && m_size)
memset(m_ptr, 0, m_size*sizeof(T));
}