From 30bcc7022d036ccd2d690e17e19f277b4fa71250 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 24 Jan 2018 15:35:45 -0500 Subject: [PATCH] Clear clang-tidy warnings --- integer.cpp | 40 +++++++++++++++------------------------- tea.cpp | 15 +++++++++------ 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/integer.cpp b/integer.cpp index 833bb3cd..e9846bde 100644 --- a/integer.cpp +++ b/integer.cpp @@ -3645,32 +3645,24 @@ std::istream& operator>>(std::istream& in, Integer &a) return in; } +// Ensure base 10 is default +inline int FlagToBase(long f) { + return f == std::ios::hex ? 16 : (f == std::ios::oct ? 8 : 10); +} + +inline char FlagToSuffix(long f) { + return f == std::ios::hex ? 'h' : (f == std::ios::oct ? 'o' : '.'); +} + +// Ensure base 10 is default std::ostream& operator<<(std::ostream& out, const Integer &a) { // Get relevant conversion specifications from ostream. - const long f = out.flags() & std::ios::basefield; // Get base digits. - int base, block; - char suffix; - switch(f) - { - case std::ios::oct : - base = 8; - block = 8; - suffix = 'o'; - break; - case std::ios::hex : - base = 16; - block = 4; - suffix = 'h'; - break; - default : - base = 10; - block = 3; - suffix = '.'; - } + const long f = out.flags() & std::ios::basefield; + const int base = FlagToBase(f); + const char suffix = FlagToSuffix(f); Integer temp1=a, temp2; - if (a.IsNegative()) { out << '-'; @@ -3698,8 +3690,6 @@ std::ostream& operator<<(std::ostream& out, const Integer &a) while (i--) { out << s[i]; -// if (i && !(i%block)) -// out << ","; } #ifdef CRYPTOPP_USE_STD_SHOWBASE @@ -3873,7 +3863,7 @@ void PositiveSubtract(Integer &diff, const Integer &a, const Integer& b) word borrow = Subtract(diff.reg, a.reg, b.reg, bSize); CopyWords(diff.reg+bSize, a.reg+bSize, aSize-bSize); borrow = Decrement(diff.reg+bSize, aSize-bSize, borrow); - CRYPTOPP_ASSERT(!borrow); + CRYPTOPP_ASSERT(!borrow); CRYPTOPP_UNUSED(borrow); diff.sign = Integer::POSITIVE; } else if (aSize == bSize) @@ -3894,7 +3884,7 @@ void PositiveSubtract(Integer &diff, const Integer &a, const Integer& b) word borrow = Subtract(diff.reg, b.reg, a.reg, aSize); CopyWords(diff.reg+aSize, b.reg+aSize, bSize-aSize); borrow = Decrement(diff.reg+aSize, bSize-aSize, borrow); - CRYPTOPP_ASSERT(!borrow); + CRYPTOPP_ASSERT(!borrow); CRYPTOPP_UNUSED(borrow); diff.sign = Integer::NEGATIVE; } } diff --git a/tea.cpp b/tea.cpp index 7ca65367..30e75832 100644 --- a/tea.cpp +++ b/tea.cpp @@ -9,6 +9,9 @@ NAMESPACE_BEGIN(CryptoPP) static const word32 DELTA = 0x9e3779b9; typedef BlockGetAndPut Block; +#define UINT32_CAST(x) ((word32*)(void*)(x)) +#define CONST_UINT32_CAST(x) ((const word32*)(const void*)(x)) + void TEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) { AssertValidKeyLength(length); @@ -98,10 +101,10 @@ void BTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by CRYPTOPP_ASSERT(IsAlignedOn(outBlock,GetAlignmentOf())); unsigned int n = m_blockSize / 4; - word32 *v = (word32*)(void *)outBlock; - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, (const word32*)(void *)inBlock, m_blockSize); + word32 *v = UINT32_CAST(outBlock); + ConditionalByteReverse(BIG_ENDIAN_ORDER, v, CONST_UINT32_CAST(inBlock), m_blockSize); - word32 y = v[0], z = v[n-1], e; + word32 y, z = v[n-1], e; word32 p, q = 6+52/n; word32 sum = 0; @@ -128,10 +131,10 @@ void BTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by CRYPTOPP_ASSERT(IsAlignedOn(outBlock,GetAlignmentOf())); unsigned int n = m_blockSize / 4; - word32 *v = (word32*)(void *)outBlock; - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, (const word32*)(void *)inBlock, m_blockSize); + word32 *v = UINT32_CAST(outBlock); + ConditionalByteReverse(BIG_ENDIAN_ORDER, v, CONST_UINT32_CAST(inBlock), m_blockSize); - word32 y = v[0], z = v[n-1], e; + word32 y = v[0], z, e; word32 p, q = 6+52/n; word32 sum = q * DELTA;