From 2b7dba4fa65ab72e75d6867468eeb1da40390daf Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 14 Jan 2016 19:08:56 -0500 Subject: [PATCH] Suppressed false positives on -Wcast-align warning --- cryptlib.h | 13 +++++++++++-- misc.cpp | 4 ++++ misc.h | 9 +++++++++ secblock.h | 11 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cryptlib.h b/cryptlib.h index ac6e8814..7dfa1ca4 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -99,7 +99,11 @@ class RandomNumberGenerator; class BufferedTransformation; //! \brief Specifies a direction for a cipher to operate -enum CipherDir {ENCRYPTION, DECRYPTION}; +enum CipherDir { + //! \brief the cipher is performing encryption + ENCRYPTION, + //! \brief the cipher is performing decryption + DECRYPTION}; //! \brief Represents infinite time const unsigned long INFINITE_TIME = ULONG_MAX; @@ -113,7 +117,12 @@ struct EnumToType }; //! \brief Provides the byte ordering -enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1}; +enum ByteOrder { + //! \brief byte order is little-endian + LITTLE_ENDIAN_ORDER = 0, + //! \brief byte order is big-endian + BIG_ENDIAN_ORDER = 1}; + //! \brief Provides a constant for LittleEndian typedef EnumToType LittleEndian; //! \brief Provides a constant for BigEndian diff --git a/misc.cpp b/misc.cpp index 1c465f43..da411ffb 100644 --- a/misc.cpp +++ b/misc.cpp @@ -10,6 +10,10 @@ # endif #endif +#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE +# pragma GCC diagnostic ignored "-Wcast-align" +#endif + #ifndef CRYPTOPP_IMPORTS #include "misc.h" diff --git a/misc.h b/misc.h index 2f165e3e..bdac4fb9 100644 --- a/misc.h +++ b/misc.h @@ -1047,6 +1047,11 @@ template<> inline void SecureWipeBuffer(word64 *buf, size_t n) template inline void SecureWipeArray(T *buf, size_t n) { +#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif + if (sizeof(T) % 8 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) SecureWipeBuffer((word64 *)buf, n * (sizeof(T)/8)); else if (sizeof(T) % 4 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) @@ -1055,6 +1060,10 @@ inline void SecureWipeArray(T *buf, size_t n) SecureWipeBuffer((word16 *)buf, n * (sizeof(T)/2)); else SecureWipeBuffer((byte *)buf, n * sizeof(T)); + +#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE +# pragma GCC diagnostic pop +#endif } //! \brief Converts a wide character C-string to a multibyte string diff --git a/secblock.h b/secblock.h index 715ee1f6..011af0e4 100644 --- a/secblock.h +++ b/secblock.h @@ -408,6 +408,12 @@ public: size_type max_size() const {return STDMAX(m_fallbackAllocator.max_size(), S);} private: + +#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif + #ifdef __BORLANDC__ T* GetAlignedArray() {return m_array;} T m_array[S]; @@ -415,6 +421,11 @@ private: T* GetAlignedArray() {return (CRYPTOPP_BOOL_ALIGN16 && T_Align16) ? (T*)(((byte *)m_array) + (0-(size_t)m_array)%16) : m_array;} CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16 && T_Align16) ? S+8/sizeof(T) : S]; #endif + +#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE +# pragma GCC diagnostic pop +#endif + A m_fallbackAllocator; bool m_allocated; };