Skip to content

Commit

Permalink
Cleared Coverity finding CID 170385 (UNINIT_CTOR) (Issue 293)
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Sep 21, 2016
1 parent c298dfd commit 584f2f2
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions integer.cpp
Expand Up @@ -204,32 +204,39 @@ static word AtomicInverseModPower2(word A)
class DWord
{
public:
// Converity finding on default ctor. We've isntrumented the code,
// and cannot uncover a case where it affects a result.
#if (defined(__COVERITY__) || CRYPTOPP_DEBUG) && defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
// Repeating pattern of 1010 for debug builds to break things...
DWord() : m_whole(0) {memset(&m_whole, 0xa, sizeof(m_whole));}
#elif (defined(__COVERITY__) || CRYPTOPP_DEBUG) && !defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
// Repeating pattern of 1010 for debug builds to break things...
DWord() : m_halfs() {memset(&m_halfs, 0xaa, sizeof(m_halfs));}
#if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
DWord() : m_whole() { }
#else
DWord() {}
DWord() : m_halfs() { }
#endif

#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
explicit DWord(word low) : m_whole(low) {}
explicit DWord(word low) : m_whole(low) { }
#else
explicit DWord(word low)
explicit DWord(word low) : m_halfs()
{
m_halfs.low = low;
m_halfs.high = 0;
}
#endif

DWord(word low, word high)
#if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
DWord(word low, word high) : m_whole()
#else
DWord(word low, word high) : m_halfs()
#endif
{
#if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
# if defined(IS_LITTLE_ENDIAN)
const word t[2] = {low,high};
memcpy(&m_whole, &t, sizeof(m_whole));
# else
const word t[2] = {high,low};
memcpy(&m_whole, &t, sizeof(m_whole));
# endif
#else
m_halfs.low = low;
m_halfs.high = high;
#endif
}

static DWord Multiply(word a, word b)
Expand Down Expand Up @@ -312,6 +319,8 @@ class DWord
#endif
}

// TODO: When NATIVE_DWORD is in effect, we access high and low, which are inactive
// union members, and that's UB. Also see http://stackoverflow.com/q/11373203.
word GetLowHalf() const {return m_halfs.low;}
word GetHighHalf() const {return m_halfs.high;}
word GetHighHalfAsBorrow() const {return 0-m_halfs.high;}
Expand Down

1 comment on commit 584f2f2

@noloader
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see Issue 293.

Please sign in to comment.