summaryrefslogtreecommitdiff
path: root/integer.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-09-20 20:51:13 -0400
committerJeffrey Walton <noloader@gmail.com>2016-09-20 20:51:13 -0400
commit584f2f2ad11edb08755fbf2ab1e7a26375cb1d65 (patch)
tree07ed3eb1366ab96d4f26d60af46965cefb268ad5 /integer.cpp
parentc298dfdbb017076de1e2f1b6bb8ccd00fe85fb95 (diff)
downloadcryptopp-git-584f2f2ad11edb08755fbf2ab1e7a26375cb1d65.tar.gz
Cleared Coverity finding CID 170385 (UNINIT_CTOR) (Issue 293)
Diffstat (limited to 'integer.cpp')
-rw-r--r--integer.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/integer.cpp b/integer.cpp
index 1785f93a..25ba6ada 100644
--- a/integer.cpp
+++ b/integer.cpp
@@ -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)
@@ -312,6 +319,8 @@ public:
#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;}