From fe60c89ce0afca84bd5188a31f6985f341f60f5f Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Fri, 7 Apr 2023 21:20:15 -0700 Subject: [PATCH 01/15] Fix some missing va_end calls found by cppcheck --- Sources/Plasma/CoreLib/HeadSpin.cpp | 2 ++ .../Plasma/PubUtilLib/plContainer/plConfigInfo.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 79e7f7f9f7..52706e908a 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -127,6 +127,7 @@ void ErrorAssert(int line, const char* file, const char* fmt, ...) va_list args; va_start(args, fmt); vsnprintf(msg, std::size(msg), fmt, args); + va_end(args); #if defined(HS_DEBUGGING) #if defined(_MSC_VER) if (s_GuiAsserts) @@ -221,6 +222,7 @@ void DebugMsg(const char* fmt, ...) va_list args; va_start(args, fmt); vsnprintf(msg, std::size(msg), fmt, args); + va_end(args); fprintf(stderr, "%s\n", msg); #ifdef _MSC_VER diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp index cdba2c60da..94ce3647e0 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp @@ -268,8 +268,10 @@ ST::string plConfigInfo::GetValueIn(const ST::string & key, const ST::string & d if (HasSection(section)) { plKeysAndValues & kv = fSections[section]; - if (kv.HasKey(key)) + if (kv.HasKey(key)) { + va_end(sections); return kv.GetValue(key,defval,outFound); + } } section = va_arg(sections,const char *); } @@ -303,8 +305,10 @@ int plConfigInfo::GetValueIn(const ST::string & key, int defval, bool * outFound if (HasSection(section)) { plKeysAndValues & kv = fSections[section]; - if (kv.HasKey(key)) + if (kv.HasKey(key)) { + va_end(sections); return kv.GetValue(key,defval,outFound); + } } section = va_arg(sections,const char *); } @@ -338,8 +342,10 @@ double plConfigInfo::GetValueIn(const ST::string & key, double defval, bool * ou if (HasSection(section)) { plKeysAndValues & kv = fSections[section]; - if (kv.HasKey(key)) + if (kv.HasKey(key)) { + va_end(sections); return kv.GetValue(key,defval,outFound); + } } section = va_arg(sections,const char *); } From e52777c63a8c63291b53b68c7ffe9b2226abad9f Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Fri, 7 Apr 2023 21:21:22 -0700 Subject: [PATCH 02/15] Fix multiple definitions of plAVIWriter In theory there's no way this would ever really cause issues, but it's easy enough to resolve by shuffling ifdefs around. --- .../Plasma/PubUtilLib/plGImage/plAVIWriter.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp index 2b971dcea6..e10bf67b78 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp @@ -63,9 +63,9 @@ plProfile_CreateTimer("AviCapture", "RenderSetup", AviCapture); bool plAVIWriter::fInitialized = false; -#if HS_BUILD_FOR_WIN32 class plAVIWriterImp : public plAVIWriter { +#if HS_BUILD_FOR_WIN32 protected: PAVIFILE fFileHandle; PAVISTREAM fStreamHandle; @@ -81,6 +81,7 @@ class plAVIWriterImp : public plAVIWriter void IFillBitmapInfo(BITMAPINFOHEADER* inf, plPipeline* pipeline); bool ICaptureFrame(plPipeline* pipeline); +#endif public: plAVIWriterImp(); @@ -93,21 +94,6 @@ class plAVIWriterImp : public plAVIWriter bool Open(const char* fileName, plPipeline* pipeline) override; void Close() override; }; -#else -class plAVIWriterImp : public plAVIWriter -{ -public: - plAVIWriterImp(); - virtual ~plAVIWriterImp(); - - bool MsgReceive(plMessage* msg) override; - - void Shutdown() override; - - bool Open(const char* fileName, plPipeline* pipeline) override; - void Close() override; -}; -#endif plAVIWriter::~plAVIWriter() { From b1561ea03b6b07d756e4df3d1ca85e3874a5fa32 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 14:07:00 -0700 Subject: [PATCH 03/15] Clang supports __builtin_unreacheable --- Sources/Plasma/CoreLib/HeadSpin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 0f0ce3517e..ffafc38f65 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -353,7 +353,7 @@ void DebugMsg(const char* fmt, ...); #if defined(_MSC_VER) #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); __assume(0); break; -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__) #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); __builtin_unreachable(); break; #else #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; From 0b2b5d820199dce2a92c89b7e57b17a83da05108 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 14:11:59 -0700 Subject: [PATCH 04/15] Fix potential access violation in avatar brains --- Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h index e7540d2e06..4c84c4a0fe 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h @@ -239,7 +239,7 @@ class plArmatureMod : public plArmatureModBase size_t GetBrainCount() const { return fBrains.size(); } plArmatureBrain *GetNextBrain(plArmatureBrain *brain); - plArmatureBrain *GetBrain(size_t index) const { if (index <= fBrains.size()) return fBrains.at(index); else return nullptr; } + plArmatureBrain *GetBrain(size_t index) const { if (index < fBrains.size()) return fBrains.at(index); else return nullptr; } plArmatureBrain *FindBrainByClass(uint32_t classID) const; void TurnToPoint(hsPoint3 &point); From d27b72aef022f4c9a0b36968d424c124d288721a Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 14:12:32 -0700 Subject: [PATCH 05/15] Fix unreachable check in NetMsg screener Pretty sure the intention was to filter out non-attach ref messages, but the default case was allowing them through before the ref message check ever ran. --- .../PubUtilLib/plNetClient/plNetClientMsgScreener.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp index dced616154..3ada9088bc 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp @@ -167,12 +167,12 @@ bool plNetClientMsgScreener::IScreenIncoming(const plMessage* msg) const return true; } default: + // Toss non-attach plRefMsgs + if (plFactory::DerivesFrom(CLASS_INDEX_SCOPED(plRefMsg), msg->ClassIndex())) + return false; + // Default allow everything else, otherweise we // might break something that we really shouldn't... return true; } - - // Toss non-attach plRefMsgs - if (plFactory::DerivesFrom(CLASS_INDEX_SCOPED(plRefMsg), msg->ClassIndex())) - return false; } From c5713f0130f574a53a24e1c54ed64e748096647e Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:24:27 -0700 Subject: [PATCH 06/15] Fix invalid throw statement --- Sources/Plasma/PubUtilLib/plGImage/plFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index c7603d8c18..33e26fce55 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -1715,7 +1715,7 @@ class plBDFCharsParser : public plBDFSectParser { // If we're doing data, all lines are hex values until we hit "ENDCHAR" if( fRowsLeft == 0 ) - throw; + throw false; int hDigit; for( hDigit = 0; *keyword != 0 && hDigit < fBytesWide; hDigit++, keyword += 2 ) From 41cc375e89ce5af418570caade25aad78184d238 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:26:38 -0700 Subject: [PATCH 07/15] Fix potential overflow iterating an hsBitVector Co-Authored-By: dgelessus --- Sources/Plasma/CoreLib/hsBitVector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsBitVector.cpp b/Sources/Plasma/CoreLib/hsBitVector.cpp index 3fb023d6e4..174a5df2e6 100644 --- a/Sources/Plasma/CoreLib/hsBitVector.cpp +++ b/Sources/Plasma/CoreLib/hsBitVector.cpp @@ -160,15 +160,15 @@ int hsBitIterator::Begin() { fCurrent = -1; fCurrVec = -1; - int i; + unsigned int i; for( i = 0; i < fBits.fNumBitVectors; i++ ) { if( fBits.fBitVectors[i] ) { - int j; + unsigned int j; for( j = 0; j < 32; j++ ) { - if( fBits.fBitVectors[i] & (1 << j) ) + if (fBits.fBitVectors[i] & (1u << j)) { fCurrVec = i; fCurrBit = j; From 1fef9f9875dec137110d79214c0f7dc03b810b57 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:27:04 -0700 Subject: [PATCH 08/15] Catch null dereference with avatar particle systems There's one spot that does actually appear to call this with nullptr, so I'm not sure how this hasn't been causing crashes... Co-Authored-By: Adam Johnson --- Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 26c35d92ca..cc478de088 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -859,6 +859,16 @@ void plArmatureMod::SpawnAt(int spawnNum, double time) void plArmatureMod::SetFollowerParticleSystemSO(plSceneObject *follower) { + if (!follower) { + if (fFollowerParticleSystemSO) { + plAttachMsg* attMsg = new plAttachMsg(GetTarget(0)->GetKey(), fFollowerParticleSystemSO, plRefMsg::kOnRemove, GetKey()); + plgDispatch::MsgSend(attMsg); + } + + fFollowerParticleSystemSO = follower; + return; + } + // TODO: Check for old one and clean up. hsPoint3 trans = GetTarget(0)->GetLocalToWorld().GetTranslate() - follower->GetLocalToWorld().GetTranslate(); From 2a83e8be066d8e294d87e9c182e0e575a6b9d45d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:28:07 -0700 Subject: [PATCH 09/15] Type the fixed locations enum as uint32 --- Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h b/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h index 340e094aba..3ced824c87 100644 --- a/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h +++ b/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h @@ -79,7 +79,7 @@ class plLocation uint32_t fSequenceNumber; uint16_t fFlags; - enum + enum : uint32_t { kGlobalFixedLocIdx = 0, // Fixed keys go here, think of as "global,fixed,keys" kSceneViewerLocIdx = 1, From 4b0c1cd11ffcdd591c0d91e032a0b20c66409003 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:28:34 -0700 Subject: [PATCH 10/15] Ensure variable is initialized before passing reference --- Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index e1aed99d69..eba581dc1a 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -283,7 +283,7 @@ uint32_t plSecureStream::IRead(uint32_t bytes, void* buffer) { if (fRef == INVALID_HANDLE_VALUE) return 0; - uint32_t numItems; + uint32_t numItems = 0; #if HS_BUILD_FOR_WIN32 bool success = (ReadFile(fRef, buffer, bytes, (LPDWORD)&numItems, nullptr) != 0); #elif HS_BUILD_FOR_UNIX From 53731af8f2fe04eca590e0039f4ea0a1a3f3dbbe Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:29:17 -0700 Subject: [PATCH 11/15] Use unsigned ints for waveset graphs Co-Authored-By: dgelessus --- .../PubUtilLib/plDrawable/plWaveSet7.cpp | 48 +++++++------------ .../Plasma/PubUtilLib/plDrawable/plWaveSet7.h | 10 ++-- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.cpp index e17ab815a5..c5ea01a90f 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.cpp @@ -4035,13 +4035,11 @@ void plWaveSet7::ICreateGraphEdgeLayer(hsGMaterial* mat, int iPass) void plWaveSet7::ICreateGraphShoreMaterials() { - int i; - for( i = 0; i < kGraphShorePasses; i++ ) - { + for (size_t i = 0; i < kGraphShorePasses; i++) { // Create our material // and send ourselves a ref. hsGMaterial* mat = ICreateEmptyMaterial("GraphShoreMat", kRefGraphShoreMat, i); - + // GraphShoreMat's are the materials used to generate the shore texture layers // which are then used on rendering the shore to the screen. @@ -4065,17 +4063,16 @@ void plWaveSet7::ICreateGraphShoreMaterials() } -void plWaveSet7::IAddGraphVShader(hsGMaterial* mat, int iPass) +void plWaveSet7::IAddGraphVShader(hsGMaterial* mat, size_t iPass) { - if( !fGraphVShader[iPass] ) - { + if (!fGraphVShader[iPass]) { plShader* vShader = new plShader; ST::string buff = ST::format("{}_GraphVS_{}", GetKey()->GetName(), iPass); hsgResMgr::ResMgr()->NewKey(buff, vShader, GetKey()->GetUoid().GetLocation()); vShader->SetIsPixelShader(false); vShader->SetNumConsts(plGraphVS::kNumConsts); - + vShader->SetVector(plGraphVS::kNumericConsts, 0, 0.5f, 1.f, 2.f); vShader->SetVector(plGraphVS::kPiConsts, 1.f / hsConstants::two_pi, hsConstants::half_pi, @@ -4102,10 +4099,9 @@ void plWaveSet7::IAddGraphVShader(hsGMaterial* mat, int iPass) IAddShaderToLayers(mat, 0, 2, plLayRefMsg::kVertexShader, fGraphVShader[iPass]); } -void plWaveSet7::IAddGraphPShader(hsGMaterial* mat, int iPass) +void plWaveSet7::IAddGraphPShader(hsGMaterial* mat, size_t iPass) { - if( !fGraphPShader[iPass] ) - { + if (!fGraphPShader[iPass]) { plShader* pShader = new plShader; ST::string buff = ST::format("{}_GraphPS_{}", GetKey()->GetName(), iPass); hsgResMgr::ResMgr()->NewKey(buff, pShader, GetKey()->GetUoid().GetLocation()); @@ -4245,7 +4241,7 @@ void plWaveSet7::ISetupShoreLayers(hsGMaterial* mat) IAddShorePixelShader(mat); } -void plWaveSet7::IInitGraph(int iPass) +void plWaveSet7::IInitGraph(size_t iPass) { GraphState& gs = fGraphState[iPass]; plShader* shader = fGraphVShader[iPass]; @@ -4323,33 +4319,27 @@ void plWaveSet7::IInitGraph(int iPass) IUpdateGraphShader(0, iPass); } -void plWaveSet7::IShuffleDownGraphs(int iPass) +void plWaveSet7::IShuffleDownGraphs(size_t iPass) { - int i; - for( i = iPass+1; i < kGraphShorePasses; i++ ) - { + for (size_t i = iPass+1; i < kGraphShorePasses; i++) { fGraphState[i-1] = fGraphState[i]; fGraphVShader[i-1]->CopyConsts(fGraphVShader[i]); } IInitGraph(kGraphShorePasses-1); } -void plWaveSet7::IUpdateGraphShader(float dt, int iPass) +void plWaveSet7::IUpdateGraphShader(float dt, size_t iPass) { - if( fGraphShoreDraw[iPass] ) - { + if (fGraphShoreDraw[iPass]) { GraphState& gs = fGraphState[iPass]; plShader* shader = fGraphVShader[iPass]; gs.fAge += dt; float rads = gs.fAge * gs.fInvLife; - if (rads >= hsConstants::pi) - { + if (rads >= hsConstants::pi) { // Recycle this one and restart the upper. IShuffleDownGraphs(iPass); - } - else - { + } else { float sinAge = hsFastMath::SinInRange(rads); shader->SetVector(plGraphVS::kAmplitude, @@ -4380,12 +4370,8 @@ void plWaveSet7::IUpdateGraphShader(float dt, int iPass) void plWaveSet7::IUpdateGraphShaders(plPipeline* pipe, float dt) { - if( fGraphShoreDraw[0] ) - { - int i; - for( i = kGraphShorePasses-1; i >= 0; i-- ) - { - IUpdateGraphShader(dt, i); - } + if (fGraphShoreDraw[0]) { + for (size_t i = kGraphShorePasses; i > 0; i--) + IUpdateGraphShader(dt, i-1); } } diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h index 7ac60d4f9a..e64c2b9bd2 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h +++ b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h @@ -424,11 +424,11 @@ class plWaveSet7 : public plWaveSetBase void ISetupDecal(hsGMaterial* mat); void ICheckDecalEnvLayers(hsGMaterial* mat); - void IAddGraphPShader(hsGMaterial* mat, int iPass); - void IAddGraphVShader(hsGMaterial* mat, int iPass); - void IUpdateGraphShader(float dt, int iPass); - void IInitGraph(int iPass); - void IShuffleDownGraphs(int iPass); + void IAddGraphPShader(hsGMaterial* mat, size_t iPass); + void IAddGraphVShader(hsGMaterial* mat, size_t iPass); + void IUpdateGraphShader(float dt, size_t iPass); + void IInitGraph(size_t iPass); + void IShuffleDownGraphs(size_t iPass); // type is either plLayRefMsg::kVertexShader or plLayRefMsg::kPixelShader. void IAddShaderToLayers(hsGMaterial* mat, int iFirst, int iLast, uint8_t type, plShader* shader); From ff257dabb189259e57978fa53076ca7f327670d9 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 8 Apr 2023 20:29:54 -0700 Subject: [PATCH 12/15] Catch hypothetical negative shift in shadow master Co-Authored-By: dgelessus --- Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp index caaad1178a..42d428c28f 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp @@ -88,10 +88,11 @@ void plShadowMaster::SetGlobalMaxSize(uint32_t s) int i; for( i = 31; i >= 0; i-- ) { - if( (1 << i) & s ) + if ((1u << i) & s) break; } - s = 1 << i; + hsAssert(i >= 0, "Invalid non-POT shadow size"); + s = 1u << i; } if( s > kMaxMaxGlobalSize ) From a1974808bdada45a3a4275e482eba79c2e5855fe Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 9 Apr 2023 16:02:04 -0700 Subject: [PATCH 13/15] Explicitly cast size_t to uint16_t in a few loops We're already asserting that the size of the containers will fit in a uint16_t, but this was getting flagged by CodeQL as a potential overflow. --- Sources/Plasma/PubUtilLib/plPipeline/plCullTree.cpp | 9 +++++---- Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp | 8 +++----- Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp | 6 ++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plCullTree.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plCullTree.cpp index 22dcfd9129..4207dfae7b 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plCullTree.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plCullTree.cpp @@ -855,8 +855,9 @@ int16_t plCullTree::IMakePolySubTree(const plCullPoly& poly) const /////////////////////////////////////////////////////////////////// void plCullTree::IVisPolyShape(const plCullPoly& poly, bool dark) const { - uint16_t vertStart = (uint16_t)fVisVerts.size(); - + hsAssert(poly.fVerts.size() < std::numeric_limits::max(), "Too many verts"); + uint16_t vertStart = uint16_t(fVisVerts.size()); + hsColorRGBA color; if( dark ) color.Set(0.2f, 0.2f, 0.2f, 1.f); @@ -871,7 +872,7 @@ void plCullTree::IVisPolyShape(const plCullPoly& poly, bool dark) const } if( !dark ) { - for (uint16_t i = 2; i < poly.fVerts.size(); i++) + for (uint16_t i = 2; i < uint16_t(poly.fVerts.size()); i++) { fVisTris.emplace_back(vertStart); fVisTris.emplace_back(vertStart + i-1); @@ -880,7 +881,7 @@ void plCullTree::IVisPolyShape(const plCullPoly& poly, bool dark) const } else { - for (uint16_t i = 2; i < poly.fVerts.size(); i++) + for (uint16_t i = 2; i < uint16_t(poly.fVerts.size()); i++) { fVisTris.emplace_back(vertStart); fVisTris.emplace_back(vertStart + i); diff --git a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp index 97b5cf0622..6bc73baf7d 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp @@ -476,16 +476,14 @@ bool plPageTreeMgr::IBuildSpaceTree() bool plPageTreeMgr::IRefreshTree(plPipeline* pipe) { hsAssert(fNodes.size() < std::numeric_limits::max(), "Too many nodes"); - for (uint16_t i = 0; i < fNodes.size(); ++i) - { + for (uint16_t i = 0; i < uint16_t(fNodes.size()); ++i) { plSceneNode* node = fNodes[i]; - if (node->GetSpaceTree()->IsDirty()) - { + if (node->GetSpaceTree()->IsDirty()) { node->GetSpaceTree()->Refresh(); GetSpaceTree()->MoveLeaf(i, node->GetSpaceTree()->GetWorldBounds()); - if (!node->GetSpaceTree()->IsEmpty() && fSpaceTree->HasLeafFlag(i, plSpaceTreeNode::kDisabled) ) + if (!node->GetSpaceTree()->IsEmpty() && fSpaceTree->HasLeafFlag(i, plSpaceTreeNode::kDisabled)) fSpaceTree->SetLeafFlag(i, plSpaceTreeNode::kDisabled, false); } } diff --git a/Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp b/Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp index 3188127233..2bd4da65c2 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plSceneNode.cpp @@ -201,11 +201,9 @@ plSpaceTree* plSceneNode::ITrashSpaceTree() void plSceneNode::IDirtySpaceTree() { hsAssert(fDrawPool.size() < std::numeric_limits::max(), "Too many nodes"); - for (uint16_t i = 0; i < fDrawPool.size(); ++i) - { + for (uint16_t i = 0; i < uint16_t(fDrawPool.size()); ++i) { plDrawable* drawable = fDrawPool[i]; - if (drawable && drawable->GetSpaceTree()->IsDirty() ) - { + if (drawable && drawable->GetSpaceTree()->IsDirty()) { drawable->GetSpaceTree()->Refresh(); fSpaceTree->MoveLeaf(i, drawable->GetSpaceTree()->GetWorldBounds()); } From c8592c603e970726f7b1b281f7e3f7d4081aeaf3 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 9 Apr 2023 16:07:46 -0700 Subject: [PATCH 14/15] Fix hypothetical uint multiplication overflow --- Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp index f082b0e018..ddc9d8cd83 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp @@ -217,7 +217,7 @@ void plGeometrySpan::IUnShareData() { uint8_t* oldVtxData = fVertexData; - uint32_t size = GetVertexSize( fFormat ); + size_t size = GetVertexSize( fFormat ); fVertexData = new uint8_t[ size * fNumVerts ]; memcpy( fVertexData, oldVtxData, size * fNumVerts ); @@ -445,9 +445,6 @@ void plGeometrySpan::IDuplicateUniqueData( const plGeometrySpan *source ) void plGeometrySpan::CopyFrom( const plGeometrySpan *source ) { - uint32_t size; - - // Just to make sure ClearBuffers(); @@ -458,7 +455,7 @@ void plGeometrySpan::CopyFrom( const plGeometrySpan *source ) if (source->fVertexData != nullptr) { - size = GetVertexSize( fFormat ); + size_t size = GetVertexSize( fFormat ); fVertexData = new uint8_t[ size * fNumVerts ]; memcpy( fVertexData, source->fVertexData, size * fNumVerts ); From 3db7cdb844e7affc3745f5c97407a4c89dd37e03 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 9 Apr 2023 17:00:21 -0700 Subject: [PATCH 15/15] Fix plAvBrainCoop printf format specifier Co-Authored-By: dgelessus --- Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp index 418bf29dcc..6166b27226 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp @@ -151,7 +151,7 @@ bool plAvBrainCoop::RelayNotifyMsg(plNotifyMsg *msg) proMultiStageEventData * mtevt = static_cast(msg->FindEventRecord(proEventData::kMultiStage)); if(mtevt) - DebugMsg("COOP: Relaying multi-stage event to %d recipients (via plAvBrainCoop)", fRecipients.size()); + DebugMsg("COOP: Relaying multi-stage event to %zu recipients (via plAvBrainCoop)", fRecipients.size()); if(fRecipients.size() != 0) {