From 8e9618167922134cf07d11fb94ec56ccffc46793 Mon Sep 17 00:00:00 2001 From: Adam Heinermann Date: Sun, 17 Nov 2024 02:10:24 -0800 Subject: [PATCH] chore(big): style and warning fixes --- storm/Big.cpp | 2 +- storm/big/Ops.cpp | 20 +++++++++----------- storm/big/Ops.hpp | 8 ++++---- storm/thread/win/S_Thread.cpp | 4 ---- test/Big.cpp | 8 ++++++-- test/Test.hpp | 8 ++++---- test/big/Ops.cpp | 2 ++ 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/storm/Big.cpp b/storm/Big.cpp index 8723c94..97a36e8 100644 --- a/storm/Big.cpp +++ b/storm/Big.cpp @@ -46,7 +46,7 @@ void SBigDel(BigData* num) { void SBigDiv(BigData* a, BigData* b, BigData* c) { uint32_t allocCount = 0; - BigBuffer &buf = a->Stack().Alloc(&allocCount); + BigBuffer& buf = a->Stack().Alloc(&allocCount); Div(a->Primary(), buf, b->Primary(), c->Primary(), a->Stack()); diff --git a/storm/big/Ops.cpp b/storm/big/Ops.cpp index cc51358..a835267 100644 --- a/storm/big/Ops.cpp +++ b/storm/big/Ops.cpp @@ -52,12 +52,12 @@ void Div(BigBuffer& a, uint32_t* b, const BigBuffer& c, uint64_t d) { uint64_t data = 0; while (index > 0) { InsertLowPart(data, c[--index]); - a[index] = data / d; + a[index] = static_cast(data / d); data %= d; } a.Trim(); - *b = data; + *b = static_cast(data); } void Div(BigBuffer& a, BigBuffer& b, const BigBuffer& c, const BigBuffer& d, BigStack& stack) { @@ -102,7 +102,7 @@ void Div(BigBuffer& a, BigBuffer& b, const BigBuffer& c, const BigBuffer& d, Big cc.SetOffset(v12 - 1); if (t) { - a[0] = MakeLarge(cc[dCount - 1], cc[dCount]) / t; + a[0] = static_cast(MakeLarge(cc[dCount - 1], cc[dCount]) / t); } else { a[0] = cc[dCount]; } @@ -211,21 +211,21 @@ void InsertLowPart(uint64_t& value, uint32_t low) { value = (value << 32) | low; } -int32_t IsEven(const BigBuffer &num) { +int32_t IsEven(const BigBuffer& num) { return num.Count() == 0 || (num[0] & 1) == 0; } -int32_t IsOdd(const BigBuffer &num) { +int32_t IsOdd(const BigBuffer& num) { num.Trim(); return num.Count() != 0 && (num[0] & 1) != 0; } -int32_t IsOne(const BigBuffer &num) { +int32_t IsOne(const BigBuffer& num) { num.Trim(); return num.Count() == 1 && num[0] == 1; } -int32_t IsZero(const BigBuffer &num) { +int32_t IsZero(const BigBuffer& num) { num.Trim(); return num.Count() == 0; } @@ -437,8 +437,7 @@ void Sub(BigBuffer& a, const BigBuffer& b, const BigBuffer& c) { } a.SetCount(i); - // This assert does not exist in retail WoW or Starcraft. - //STORM_ASSERT(!borrow); + STORM_ASSERT(!borrow); } void Sub(BigBuffer& a, const BigBuffer& b, uint32_t c) { @@ -451,8 +450,7 @@ void Sub(BigBuffer& a, const BigBuffer& b, uint32_t c) { } a.SetCount(i); - // This assert does not exist in retail WoW or Starcraft. - //STORM_ASSERT(!borrow); + STORM_ASSERT(!borrow); } void ToBinaryAppend(TSGrowableArray& output, const BigBuffer& buffer) { diff --git a/storm/big/Ops.hpp b/storm/big/Ops.hpp index ef523db..10ec817 100644 --- a/storm/big/Ops.hpp +++ b/storm/big/Ops.hpp @@ -33,13 +33,13 @@ uint32_t HighBitPos(const BigBuffer& buffer); void InsertLowPart(uint64_t& value, uint32_t low); -int32_t IsEven(const BigBuffer &num); +int32_t IsEven(const BigBuffer& num); -int32_t IsOdd(const BigBuffer &num); +int32_t IsOdd(const BigBuffer& num); -int32_t IsOne(const BigBuffer &num); +int32_t IsOne(const BigBuffer& num); -int32_t IsZero(const BigBuffer &num); +int32_t IsZero(const BigBuffer& num); uint64_t MakeLarge(uint32_t low, uint32_t high); diff --git a/storm/thread/win/S_Thread.cpp b/storm/thread/win/S_Thread.cpp index 345ac0d..0059b67 100644 --- a/storm/thread/win/S_Thread.cpp +++ b/storm/thread/win/S_Thread.cpp @@ -1,10 +1,6 @@ #include "storm/thread/S_Thread.hpp" #include "storm/Memory.hpp" -#ifndef WINAPI -#define WINAPI -#endif - DWORD WINAPI S_Thread::s_SLaunchThread(void* threadParam) { auto params = static_cast(threadParam); auto proc = params->threadProc; diff --git a/test/Big.cpp b/test/Big.cpp index 39e38d4..e5665ec 100644 --- a/test/Big.cpp +++ b/test/Big.cpp @@ -171,6 +171,7 @@ TEST_CASE("SBigDec", "[big]") { CHECK(a->Primary()[0] == 4); } +#ifdef NDEBUG SECTION("decrements from 0") { SBigFromUnsigned(b, 0); @@ -179,6 +180,7 @@ TEST_CASE("SBigDec", "[big]") { CHECK(a->Primary().Count() == 1); CHECK(a->Primary()[0] == 0xFFFFFFFF); } +#endif } TEST_CASE("SBigDiv", "[big]") { @@ -611,8 +613,8 @@ TEST_CASE("SBigOr", "[big]") { SBigOr(a, b, c); CHECK(a->Primary().Count() == 2); - CHECK(a->Primary()[0] == uint32_t(v.first | v.second)); - CHECK(a->Primary()[1] == uint32_t((v.first | v.second) >> 32)); + CHECK(a->Primary()[0] == 0xFFFFFFFF); + CHECK(a->Primary()[1] == 0xFFFFFFFF); } SECTION("performs bitwise or on huge value") { @@ -694,6 +696,7 @@ TEST_CASE("SBigSub", "[big]") { CHECK(a->Primary()[0] == 1); } +#ifdef NDEBUG SECTION("subtracts 1 from 0") { SBigFromUnsigned(b, 0); SBigFromUnsigned(c, 1); @@ -703,6 +706,7 @@ TEST_CASE("SBigSub", "[big]") { CHECK(a->Primary().Count() == 1); CHECK(a->Primary()[0] == 0xFFFFFFFF); } +#endif } TEST_CASE("SBigToBinaryBuffer", "[big]") { diff --git a/test/Test.hpp b/test/Test.hpp index 25f37c1..990c842 100644 --- a/test/Test.hpp +++ b/test/Test.hpp @@ -4,14 +4,14 @@ class BigData; // Fixture for repetitive handling of BigData objects. struct BigDataTest { - using BigDataPtr=BigData*; + using BigDataPtr = BigData*; - BigData *num; + BigData* num; BigDataTest(); ~BigDataTest(); - BigData **operator &() { return # } + BigData** operator &() { return # } operator BigDataPtr() const { return num; } - BigData *operator->() const { return num; } + BigData* operator->() const { return num; } }; diff --git a/test/big/Ops.cpp b/test/big/Ops.cpp index 5365de0..c7c04ba 100644 --- a/test/big/Ops.cpp +++ b/test/big/Ops.cpp @@ -970,6 +970,7 @@ TEST_CASE("Sub", "[big]") { CHECK(a->Primary()[0] == 1); } +#ifdef NDEBUG SECTION("subtracts 1 from 0") { SBigFromUnsigned(b, 0); SBigFromUnsigned(c, 1); @@ -988,6 +989,7 @@ TEST_CASE("Sub", "[big]") { CHECK(a->Primary().Count() == 1); CHECK(a->Primary()[0] == 0xFFFFFFFF); } +#endif SECTION("subtracts 1 from 2") { SBigFromUnsigned(b, 2);