From 727aa8e71fd8b6e56346cd53d5a3bcdf93f3f8a7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 2 Jul 2020 15:03:12 -0700 Subject: [PATCH] Warning removal. --- core/AES.cpp | 12 ++++++------ core/Blob.hpp | 16 ++++++++-------- core/C25519.cpp | 1 + core/Path.cpp | 2 +- core/Path.hpp | 5 ++--- core/Peer.cpp | 9 +++------ core/Poly1305.hpp | 20 +++++++++++++------- core/Salsa20.cpp | 3 --- core/Topology.cpp | 1 + 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/core/AES.cpp b/core/AES.cpp index 56f7d3189..38b9adc72 100644 --- a/core/AES.cpp +++ b/core/AES.cpp @@ -170,7 +170,7 @@ void s_gfmul(const uint64_t h_high,const uint64_t h_low,uint64_t &y0,uint64_t &y // SSE shuffle parameter to reverse bytes in a 128-bit vector. static const __m128i s_sseSwapBytes = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); -static ZT_INLINE __m128i p_gmacPCLMUL128(const __m128i h, __m128i y) noexcept +static __m128i p_gmacPCLMUL128(const __m128i h, __m128i y) noexcept { y = _mm_shuffle_epi8(y, s_sseSwapBytes); __m128i t1 = _mm_clmulepi64_si128(h, y, 0x00); @@ -317,7 +317,7 @@ void AES::GMAC::update(const void *const data, unsigned int len) noexcept t3 = _mm_xor_si128(t3, _mm_slli_si128(t7, 12)); t6 = _mm_xor_si128(t6, _mm_xor_si128(t3, _mm_xor_si128(_mm_xor_si128(_mm_srli_epi32(t3, 1), t8), _mm_xor_si128(_mm_srli_epi32(t3, 2), _mm_srli_epi32(t3, 7))))); y = _mm_shuffle_epi8(t6, s_sseSwapBytes); - } while (len >= 64); + } while (likely(len >= 64)); } while (len >= 16) { @@ -565,7 +565,7 @@ void p_aesCtrInnerVAES512(unsigned int &len, const uint64_t c0, uint64_t &c1, co d0 = _mm512_aesenclast_epi128(d0, kk14); _mm512_storeu_si512(reinterpret_cast<__m512i *>(out), _mm512_xor_si512(p0, d0)); out += 64; - } while (len >= 64); + } while (likely(len >= 64)); } #define ZT_AES_VAES256 @@ -634,12 +634,12 @@ void p_aesCtrInnerVAES256(unsigned int &len, uint64_t &c0, uint64_t &c1, const u _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), _mm256_xor_si256(d0, p0)); _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 32), _mm256_xor_si256(d1, p1)); out += 64; - } while (len >= 64); + } while (likely(len >= 64)); } #endif -static void p_aesCtrInner128(unsigned int &len, uint64_t &c0, uint64_t &c1, const uint8_t *&in, uint8_t *&out, const __m128i *const k) noexcept +static ZT_INLINE void p_aesCtrInner128(unsigned int &len, uint64_t &c0, uint64_t &c1, const uint8_t *&in, uint8_t *&out, const __m128i *const k) noexcept { const __m128i k0 = k[0]; const __m128i k1 = k[1]; @@ -739,7 +739,7 @@ static void p_aesCtrInner128(unsigned int &len, uint64_t &c0, uint64_t &c1, cons _mm_prefetch(in, _MM_HINT_T0); out += 64; len -= 64; - } while (len >= 64); + } while (likely(len >= 64)); } #endif diff --git a/core/Blob.hpp b/core/Blob.hpp index 20e11d86e..b5132a206 100644 --- a/core/Blob.hpp +++ b/core/Blob.hpp @@ -32,7 +32,7 @@ struct SHA384Hash uint64_t data[6]; ZT_INLINE SHA384Hash() noexcept - { Utils::zero< 48 >(data); } + { Utils::zero(data); } explicit ZT_INLINE SHA384Hash(const void *const d) noexcept { Utils::copy< 48 >(data, d); } @@ -73,7 +73,7 @@ struct UniqueID uint64_t data[2]; ZT_INLINE UniqueID() noexcept - {} + { Utils::zero(data); } ZT_INLINE UniqueID(const uint64_t a, const uint64_t b) noexcept { @@ -93,22 +93,22 @@ struct UniqueID ZT_INLINE operator bool() const noexcept { return ((data[0] != 0) && (data[1] != 0)); } - ZT_INLINE bool operator==(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator==(const UniqueID &b) const noexcept { return ((data[0] == b.data[0]) && (data[1] == b.data[1])); } - ZT_INLINE bool operator!=(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator!=(const UniqueID &b) const noexcept { return !(*this == b); } - ZT_INLINE bool operator<(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator<(const UniqueID &b) const noexcept { return (memcmp(data, b.data, 16) < 0); } - ZT_INLINE bool operator>(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator>(const UniqueID &b) const noexcept { return (memcmp(data, b.data, 16) > 0); } - ZT_INLINE bool operator<=(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator<=(const UniqueID &b) const noexcept { return (memcmp(data, b.data, 16) <= 0); } - ZT_INLINE bool operator>=(const SHA384Hash &b) const noexcept + ZT_INLINE bool operator>=(const UniqueID &b) const noexcept { return (memcmp(data, b.data, 16) >= 0); } }; diff --git a/core/C25519.cpp b/core/C25519.cpp index 3786ca39d..b2ed79331 100644 --- a/core/C25519.cpp +++ b/core/C25519.cpp @@ -20,6 +20,7 @@ Derived from public domain code by D. J. Bernstein. #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wuninitialized" #endif using namespace ZeroTier; diff --git a/core/Path.cpp b/core/Path.cpp index 015b4c8f4..489116f06 100644 --- a/core/Path.cpp +++ b/core/Path.cpp @@ -19,7 +19,7 @@ namespace ZeroTier { bool Path::send(const RuntimeEnvironment *const RR, void *const tPtr, const void *const data, const unsigned int len, const int64_t now) noexcept { - if (RR->node->putPacket(tPtr, m_localSocket, m_addr, data, len)) { + if (likely(RR->node->putPacket(tPtr, m_localSocket, m_addr, data, len))) { m_lastOut = now; m_outMeter.log(now, len); return true; diff --git a/core/Path.hpp b/core/Path.hpp index c9dbaeeff..c05e2ff02 100644 --- a/core/Path.hpp +++ b/core/Path.hpp @@ -48,8 +48,7 @@ public: m_lastOut(0), m_latency(-1), m_addr(r) - { - } + {} /** * Send a packet via this path (last out time is also updated) @@ -95,7 +94,7 @@ public: ZT_INLINE void updateLatency(const unsigned int newMeasurement) noexcept { int lat = m_latency; - if (lat > 0) { + if (likely(lat > 0)) { m_latency = (lat + newMeasurement) / 2; } else { m_latency = newMeasurement; diff --git a/core/Peer.cpp b/core/Peer.cpp index b4af96006..0e09143b6 100644 --- a/core/Peer.cpp +++ b/core/Peer.cpp @@ -29,7 +29,7 @@ Peer::Peer(const RuntimeEnvironment *renv) : m_ephemeralPairTimestamp(0), m_lastReceive(0), m_lastSend(0), - m_lastSentHello(), + m_lastSentHello(0), m_lastWhoisRequestReceived(0), m_lastEchoRequestReceived(0), m_lastPrioritizedPaths(0), @@ -40,13 +40,10 @@ Peer::Peer(const RuntimeEnvironment *renv) : m_vMajor(0), m_vMinor(0), m_vRevision(0) -{ -} +{} Peer::~Peer() -{ - Utils::burn(m_helloMacKey, sizeof(m_helloMacKey)); -} +{ Utils::burn(m_helloMacKey, sizeof(m_helloMacKey)); } bool Peer::init(const Identity &peerIdentity) { diff --git a/core/Poly1305.hpp b/core/Poly1305.hpp index 517d4fc13..22ad4707f 100644 --- a/core/Poly1305.hpp +++ b/core/Poly1305.hpp @@ -25,24 +25,30 @@ namespace ZeroTier { class Poly1305 { public: - ZT_INLINE Poly1305() {} - ZT_INLINE Poly1305(const void *key) { this->init(key); } + ZT_INLINE Poly1305() + {} + + ZT_INLINE Poly1305(const void *key) + { this->init(key); } void init(const void *key) noexcept; - void update(const void *data,unsigned int len) noexcept; + + void update(const void *data, unsigned int len) noexcept; + void finish(void *auth) noexcept; static ZT_INLINE void compute(void *const auth, const void *const data, const unsigned int len, const void *const key) noexcept { Poly1305 p(key); - p.update(data,len); + p.update(data, len); p.finish(auth); } private: - struct { - size_t aligner; - unsigned char opaque[136]; + struct + { + size_t aligner; + unsigned char opaque[136]; } ctx; }; diff --git a/core/Salsa20.cpp b/core/Salsa20.cpp index 2f4bf2959..e81d43e1b 100644 --- a/core/Salsa20.cpp +++ b/core/Salsa20.cpp @@ -39,7 +39,6 @@ static ZT_INLINE void U32TO8_LITTLE(uint8_t *const c,const uint32_t v) { c[0] = #endif // !ZT_SALSA20_SSE #ifdef ZT_SALSA20_SSE - class _s20sseconsts { public: @@ -48,10 +47,8 @@ public: maskLo32 = _mm_shuffle_epi32(_mm_cvtsi32_si128(-1), _MM_SHUFFLE(1, 0, 1, 0)); maskHi32 = _mm_slli_epi64(maskLo32, 32); } - __m128i maskLo32, maskHi32; }; - static const _s20sseconsts s_S20SSECONSTANTS; #endif diff --git a/core/Topology.cpp b/core/Topology.cpp index 3c7f54a56..74e8b9fe2 100644 --- a/core/Topology.cpp +++ b/core/Topology.cpp @@ -131,6 +131,7 @@ struct p_RootRankingComparisonOperator return true; return bb < a->latency(); } + return false; } };