From f8682d227b1a61d29b47f6f19a7bb31d1b821524 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 7 Jun 2015 00:21:53 +0200 Subject: [PATCH] More Cppcheck fixes Former-commit-id: 62ab1caa04543da1a169812bb92a450d44f3aec1 --- include/Nazara/Core/Color.inl | 9 ++++++-- include/Nazara/Core/MemoryPool.inl | 16 +++++++------- src/Nazara/Core/Hash/SHA/Internal.cpp | 4 +++- src/Nazara/Core/HashDigest.cpp | 3 +++ src/Nazara/Core/String.cpp | 32 +++++++++++++-------------- src/Nazara/Utility/Algorithm.cpp | 2 +- src/Nazara/Utility/Skeleton.cpp | 3 +++ 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/include/Nazara/Core/Color.inl b/include/Nazara/Core/Color.inl index 8e2caa76c..2f779bee4 100644 --- a/include/Nazara/Core/Color.inl +++ b/include/Nazara/Core/Color.inl @@ -160,31 +160,37 @@ inline NzColor NzColor::FromHSV(float hue, float saturation, float value) r = value; g = v3; b = v1; + break; case 1: r = v2; g = value; b = v1; + break; case 2: r = v1; g = value; b = v3; + break; case 3: r = v1; g = v2; b = value; + break; case 4: r = v3; g = v1; b = value; + break; default: r = value; g = v1; b = v2; + break; } // RGB results from 0 to 255 @@ -289,12 +295,11 @@ inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturati float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax; float h; - if (NzNumberEquals(r, max)) h = deltaB - deltaG; else if (NzNumberEquals(g, max)) h = (1.f/3.f) + deltaR - deltaB; - else if (NzNumberEquals(b, max)) + else h = (2.f/3.f) + deltaG - deltaR; if (h < 0.f) diff --git a/include/Nazara/Core/MemoryPool.inl b/include/Nazara/Core/MemoryPool.inl index 7ee79dfa1..49241905a 100644 --- a/include/Nazara/Core/MemoryPool.inl +++ b/include/Nazara/Core/MemoryPool.inl @@ -123,14 +123,14 @@ inline T* NzMemoryPool::New(Args&&... args) inline NzMemoryPool& NzMemoryPool::operator=(NzMemoryPool&& pool) noexcept { - m_blockSize = m_blockSize; - m_canGrow = m_canGrow; - m_freeCount = m_freeCount.load(std::memory_order_relaxed); - m_freeList = std::move(m_freeList); - m_pool = std::move(m_pool); - m_previous = m_previous; - m_next = std::move(m_next); - m_size = m_size; + m_blockSize = pool.m_blockSize; + m_canGrow = pool.m_canGrow; + m_freeCount = pool.m_freeCount.load(std::memory_order_relaxed); + m_freeList = std::move(pool.m_freeList); + m_pool = std::move(pool.m_pool); + m_previous = pool.m_previous; + m_next = std::move(pool.m_next); + m_size = pool.m_size; // Si nous avons été créés par un autre pool, nous devons le faire pointer vers nous de nouveau if (m_previous) diff --git a/src/Nazara/Core/Hash/SHA/Internal.cpp b/src/Nazara/Core/Hash/SHA/Internal.cpp index 6c3177855..03fe266f4 100644 --- a/src/Nazara/Core/Hash/SHA/Internal.cpp +++ b/src/Nazara/Core/Hash/SHA/Internal.cpp @@ -588,7 +588,7 @@ void SHA256_Init(SHA_CTX* context) void SHA256_Internal_Transform(SHA_CTX* context, const nzUInt32* data) { - nzUInt32 a, b, c, d, e, f, g, h, s0, s1; + nzUInt32 a, b, c, d, e, f, g, h; nzUInt32 T1, *W256; int j; @@ -622,6 +622,8 @@ void SHA256_Internal_Transform(SHA_CTX* context, const nzUInt32* data) /* Now for the remaining rounds to 64: */ do { + nzUInt32 s0, s1; + ROUND256(a,b,c,d,e,f,g,h); ROUND256(h,a,b,c,d,e,f,g); ROUND256(g,h,a,b,c,d,e,f); diff --git a/src/Nazara/Core/HashDigest.cpp b/src/Nazara/Core/HashDigest.cpp index 62baac0aa..a66feeb84 100644 --- a/src/Nazara/Core/HashDigest.cpp +++ b/src/Nazara/Core/HashDigest.cpp @@ -104,6 +104,9 @@ nzUInt8 NzHashDigest::operator[](unsigned int pos) const NzHashDigest& NzHashDigest::operator=(const NzHashDigest& rhs) { + if (this == &rhs) + return *this; + m_hashName = rhs.m_hashName; m_digestLength = rhs.m_digestLength; diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index d2ba08601..3fddbae46 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -1097,7 +1097,7 @@ unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flag { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1139,7 +1139,7 @@ unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flag { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1280,7 +1280,7 @@ unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1322,7 +1322,7 @@ unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1456,7 +1456,7 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1478,8 +1478,8 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) break; - p++; - tIt++; + ++p; + ++tIt; } } } @@ -1496,7 +1496,7 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1518,8 +1518,8 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c if (*tIt != *p) break; - p++; - tIt++; + ++p; + ++tIt; } } } @@ -1628,7 +1628,7 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1650,8 +1650,8 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) break; - p++; - tIt++; + ++p; + ++tIt; } } } @@ -1668,7 +1668,7 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag { if (it.base() != m_sharedString->string) { - it--; + --it; if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) continue; } @@ -1690,8 +1690,8 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag if (*tIt != *p) break; - p++; - tIt++; + ++p; + ++tIt; } } } diff --git a/src/Nazara/Utility/Algorithm.cpp b/src/Nazara/Utility/Algorithm.cpp index 04ef1d4fb..7801f7f93 100644 --- a/src/Nazara/Utility/Algorithm.cpp +++ b/src/Nazara/Utility/Algorithm.cpp @@ -638,7 +638,7 @@ NzBoxf NzComputeAABB(NzSparsePtr positionPtr, unsigned int ver if (vertexCount > 0) { aabb.Set(positionPtr->x, positionPtr->y, positionPtr->z, 0.f, 0.f, 0.f); - positionPtr++; + --positionPtr; for (unsigned int i = 1; i < vertexCount; ++i) aabb.ExtendTo(*positionPtr++); diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index 616b76fd5..a12fe4ae9 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -333,6 +333,9 @@ bool NzSkeleton::IsValid() const NzSkeleton& NzSkeleton::operator=(const NzSkeleton& skeleton) { + if (this == &skeleton) + return *this; + Destroy(); if (skeleton.m_impl)