Fix clang warnings in headers (#655)

* remove superfluous semicolon

* Remove C-style casts from public headers

clang warns about them with -Wold-style-cast. It also warns about
implicitly casting away const with -Wcast-qual. Fix both by removing
unnecessary casts and converting the remaining ones to C++ casts.
pull/665/head
Marcel Raad 2018-05-11 01:59:21 +02:00 committed by Jeffrey Walton
parent a07a0e5e5f
commit 7c1d296283
11 changed files with 35 additions and 35 deletions

View File

@ -28,7 +28,7 @@ public:
ConstByteArrayParameter(const char *data = NULLPTR, bool deepCopy = false)
: m_deepCopy(false), m_data(NULLPTR), m_size(0)
{
Assign((const byte *)data, data ? strlen(data) : 0, deepCopy);
Assign(reinterpret_cast<const byte *>(data), data ? strlen(data) : 0, deepCopy);
}
/// \brief Construct a ConstByteArrayParameter
@ -53,7 +53,7 @@ public:
: m_deepCopy(false), m_data(NULLPTR), m_size(0)
{
CRYPTOPP_COMPILE_ASSERT(sizeof(typename T::value_type) == 1);
Assign((const byte *)string.data(), string.size(), deepCopy);
Assign(reinterpret_cast<const byte *>(string.data()), string.size(), deepCopy);
}
/// \brief Assign contents from a memory buffer

4
crc.h
View File

@ -34,7 +34,7 @@ public:
std::string AlgorithmName() const {return StaticAlgorithmName();}
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
protected:
void Reset() {m_crc = CRC32_NEGL;}
@ -59,7 +59,7 @@ public:
std::string AlgorithmName() const {return StaticAlgorithmName();}
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
protected:
void Reset() {m_crc = CRC32_NEGL;}

View File

@ -131,7 +131,7 @@ const unsigned long INFINITE_TIME = ULONG_MAX;
template <typename ENUM_TYPE, int VALUE>
struct EnumToType
{
static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}
static ENUM_TYPE ToEnum() {return static_cast<ENUM_TYPE>(VALUE);}
};
/// \brief Provides the byte ordering

View File

@ -865,12 +865,12 @@ public:
/// \brief Stop redirecting input
void StopRedirection() {m_target = NULLPTR;}
Behavior GetBehavior() {return (Behavior) m_behavior;}
Behavior GetBehavior() {return static_cast<Behavior>(m_behavior);}
void SetBehavior(Behavior behavior) {m_behavior=behavior;}
bool GetPassSignals() const {return (m_behavior & PASS_SIGNALS) != 0;}
void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~(word32) PASS_SIGNALS; }
void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~static_cast<word32>(PASS_SIGNALS); }
bool GetPassWaitObjects() const {return (m_behavior & PASS_WAIT_OBJECTS) != 0;}
void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~(word32) PASS_WAIT_OBJECTS; }
void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~static_cast<word32>(PASS_WAIT_OBJECTS); }
bool CanModifyInput() const
{return m_target ? m_target->CanModifyInput() : false;}
@ -1293,7 +1293,7 @@ public:
/// \details Internally, Pump() calls Pump2().
/// \note pumpMax is a \p lword, which is a 64-bit value that typically uses \p LWORD_MAX. The default
/// argument is a \p size_t that uses \p SIZE_MAX, and it can be 32-bits or 64-bits.
lword Pump(lword pumpMax=(size_t)SIZE_MAX)
lword Pump(lword pumpMax=SIZE_MAX)
{Pump2(pumpMax); return pumpMax;}
/// \brief Pump messages to attached transformation

View File

@ -168,7 +168,7 @@ public:
/// \brief Provides the digest size of the hash
/// \return the digest size of the hash, in bytes
/// \details DigestSize() returns <tt>DIGESTSIZE</tt>.
unsigned int DigestSize() const {return DIGESTSIZE;};
unsigned int DigestSize() const {return DIGESTSIZE;}
protected:
IteratedHashWithStaticTransform() {this->Init();}

26
misc.h
View File

@ -729,7 +729,7 @@ inline unsigned int TrailingZeros(word32 v)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
unsigned long result;
_BitScanForward(&result, v);
return (unsigned int)result;
return static_cast<unsigned int>(result);
#else
// from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
static const int MultiplyDeBruijnBitPosition[32] =
@ -760,7 +760,7 @@ inline unsigned int TrailingZeros(word64 v)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64))
unsigned long result;
_BitScanForward64(&result, v);
return (unsigned int)result;
return static_cast<unsigned int>(result);
#else
return word32(v) ? TrailingZeros(word32(v)) : 32 + TrailingZeros(word32(v>>32));
#endif
@ -1029,7 +1029,7 @@ inline unsigned int GetAlignmentOf()
/// If not, then the function effectively performs a modular reduction and returns true if the residue is 0
inline bool IsAlignedOn(const void *ptr, unsigned int alignment)
{
return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2((size_t)ptr, alignment) == 0 : (size_t)ptr % alignment == 0);
return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2(reinterpret_cast<size_t>(ptr), alignment) == 0 : reinterpret_cast<size_t>(ptr) % alignment == 0);
}
/// \brief Determines whether ptr is minimally aligned
@ -1184,7 +1184,7 @@ template<> inline void SecureWipeBuffer(byte *buf, size_t n)
#ifdef __GNUC__
asm volatile("rep stosb" : "+c"(n), "+D"(p) : "a"(0) : "memory");
#else
__stosb((byte *)(size_t)p, 0, n);
__stosb(reinterpret_cast<byte *>(reinterpret_cast<size_t>(p)), 0, n);
#endif
}
@ -1198,7 +1198,7 @@ template<> inline void SecureWipeBuffer(word16 *buf, size_t n)
#ifdef __GNUC__
asm volatile("rep stosw" : "+c"(n), "+D"(p) : "a"(0) : "memory");
#else
__stosw((word16 *)(size_t)p, 0, n);
__stosw(reinterpret_cast<word16 *>(reinterpret_cast<size_t>(p)), 0, n);
#endif
}
@ -1212,7 +1212,7 @@ template<> inline void SecureWipeBuffer(word32 *buf, size_t n)
#ifdef __GNUC__
asm volatile("rep stosl" : "+c"(n), "+D"(p) : "a"(0) : "memory");
#else
__stosd((unsigned long *)(size_t)p, 0, n);
__stosd(reinterpret_cast<unsigned long *>(reinterpret_cast<size_t>(p)), 0, n);
#endif
}
@ -1227,10 +1227,10 @@ template<> inline void SecureWipeBuffer(word64 *buf, size_t n)
#ifdef __GNUC__
asm volatile("rep stosq" : "+c"(n), "+D"(p) : "a"(0) : "memory");
#else
__stosq((word64 *)(size_t)p, 0, n);
__stosq(reinterpret_cast<word64 *>(reinterpret_cast<size_t>(p)), 0, n);
#endif
#else
SecureWipeBuffer((word32 *)buf, 2*n);
SecureWipeBuffer(reinterpret_cast<word32 *>(buf), 2*n);
#endif
}
@ -1275,13 +1275,13 @@ template <class T>
inline void SecureWipeArray(T *buf, size_t n)
{
if (sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
SecureWipeBuffer((word64 *)(void *)buf, n * (sizeof(T)/8));
SecureWipeBuffer(reinterpret_cast<word64 *>(static_cast<void *>(buf)), n * (sizeof(T)/8));
else if (sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
SecureWipeBuffer((word32 *)(void *)buf, n * (sizeof(T)/4));
SecureWipeBuffer(reinterpret_cast<word32 *>(static_cast<void *>(buf)), n * (sizeof(T)/4));
else if (sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
SecureWipeBuffer((word16 *)(void *)buf, n * (sizeof(T)/2));
SecureWipeBuffer(reinterpret_cast<word16 *>(static_cast<void *>(buf)), n * (sizeof(T)/2));
else
SecureWipeBuffer((byte *)(void *)buf, n * sizeof(T));
SecureWipeBuffer(reinterpret_cast<byte *>(static_cast<void *>(buf)), n * sizeof(T));
}
/// \brief Converts a wide character C-string to a multibyte string
@ -2104,7 +2104,7 @@ inline word64 UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, co
inline void UnalignedbyteNonTemplate(ByteOrder order, byte *block, byte value, const byte *xorBlock)
{
CRYPTOPP_UNUSED(order);
block[0] = (byte)(xorBlock ? (value ^ xorBlock[0]) : value);
block[0] = static_cast<byte>(xorBlock ? (value ^ xorBlock[0]) : value);
}
inline void UnalignedbyteNonTemplate(ByteOrder order, byte *block, word16 value, const byte *xorBlock)

View File

@ -47,12 +47,12 @@ public:
/// \brief Construct a ModularArithmetic
/// \param modulus congruence class modulus
ModularArithmetic(const Integer &modulus = Integer::One())
: AbstractRing<Integer>(), m_modulus(modulus), m_result((word)0, modulus.reg.size()) {}
: AbstractRing<Integer>(), m_modulus(modulus), m_result(static_cast<word>(0), modulus.reg.size()) {}
/// \brief Copy construct a ModularArithmetic
/// \param ma other ModularArithmetic
ModularArithmetic(const ModularArithmetic &ma)
: AbstractRing<Integer>(), m_modulus(ma.m_modulus), m_result((word)0, ma.m_modulus.reg.size()) {}
: AbstractRing<Integer>(), m_modulus(ma.m_modulus), m_result(static_cast<word>(0), ma.m_modulus.reg.size()) {}
/// \brief Construct a ModularArithmetic
/// \param bt BER encoded ModularArithmetic

View File

@ -80,7 +80,7 @@ public:
protected:
CipherModeBase() : m_cipher(NULLPTR) {}
inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return (unsigned int)m_register.size();}
inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return static_cast<unsigned int>(m_register.size());}
virtual void SetFeedbackSize(unsigned int feedbackSize)
{
if (!(feedbackSize == 0 || feedbackSize == BlockSize()))
@ -251,7 +251,7 @@ protected:
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
CBC_Encryption::UncheckedSetKey(key, length, params);
m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULLPTR);
m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), static_cast<byte *>(NULLPTR));
}
byte *m_stolenIV;

View File

@ -198,10 +198,10 @@ public:
#if CRYPTOPP_BOOL_ALIGN16
// TODO: Does this need the test 'size*sizeof(T) >= 16'?
if (T_Align16 && size)
return (pointer)AlignedAllocate(size*sizeof(T));
return reinterpret_cast<pointer>(AlignedAllocate(size*sizeof(T)));
#endif
return (pointer)UnalignedAllocate(size*sizeof(T));
return reinterpret_cast<pointer>(UnalignedAllocate(size*sizeof(T)));
}
/// \brief Deallocates a block of memory
@ -217,7 +217,7 @@ public:
// This will fire if SetMark(0) was called in the SecBlock
// Our self tests exercise it, disable it now.
// CRYPTOPP_ASSERT((ptr && size) || !(ptr || size));
SecureWipeArray((pointer)ptr, size);
SecureWipeArray(reinterpret_cast<pointer>(ptr), size);
#if CRYPTOPP_BOOL_ALIGN16
if (T_Align16 && size)

View File

@ -130,7 +130,7 @@ struct CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AdditiveCipherAbstractPolicy
/// \param iterationCount the number of iterations to generate the key stream
/// \sa CanOperateKeystream(), OperateKeystream(), WriteKeystream()
virtual void WriteKeystream(byte *keystream, size_t iterationCount)
{OperateKeystream(KeystreamOperation(INPUT_NULL | (KeystreamOperationFlags)IsAlignedOn(keystream, GetAlignment())), keystream, NULLPTR, iterationCount);}
{OperateKeystream(KeystreamOperation(INPUT_NULL | static_cast<KeystreamOperationFlags>(IsAlignedOn(keystream, GetAlignment()))), keystream, NULLPTR, iterationCount);}
/// \brief Flag indicating
/// \returns true if the stream can be generated independent of the transformation input, false otherwise

8
trap.h
View File

@ -64,8 +64,8 @@
# define CRYPTOPP_ASSERT(exp) { \
if (!(exp)) { \
std::ostringstream oss; \
oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
<< (int)(__LINE__) << "): " << (char*)(__func__) \
oss << "Assertion failed: " << __FILE__ << "(" \
<< __LINE__ << "): " << __func__ \
<< std::endl; \
std::cerr << oss.str(); \
raise(SIGTRAP); \
@ -75,8 +75,8 @@
# define CRYPTOPP_ASSERT(exp) { \
if (!(exp)) { \
std::ostringstream oss; \
oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
<< (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \
oss << "Assertion failed: " << __FILE__ << "(" \
<< __LINE__ << "): " << __FUNCTION__ \
<< std::endl; \
std::cerr << oss.str(); \
if (IsDebuggerPresent()) {DebugBreak();} \