Skip to content

Commit

Permalink
Merge pull request #1371 from dpogue/cppcheck
Browse files Browse the repository at this point in the history
Various small fixes identified by cppcheck
  • Loading branch information
Hoikas authored Nov 3, 2023
2 parents 55ba2ae + 3db7cdb commit 1c4209c
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 88 deletions.
2 changes: 2 additions & 0 deletions Sources/Plasma/CoreLib/HeadSpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/CoreLib/HeadSpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/CoreLib/hsBitVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool plAvBrainCoop::RelayNotifyMsg(plNotifyMsg *msg)

proMultiStageEventData * mtevt = static_cast<proMultiStageEventData *>(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)
{
Expand Down
12 changes: 9 additions & 3 deletions Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
}
Expand Down Expand Up @@ -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 *);
}
Expand Down Expand Up @@ -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 *);
}
Expand Down
7 changes: 2 additions & 5 deletions Sources/Plasma/PubUtilLib/plDrawable/plGeometrySpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -445,9 +445,6 @@ void plGeometrySpan::IDuplicateUniqueData( const plGeometrySpan *source )

void plGeometrySpan::CopyFrom( const plGeometrySpan *source )
{
uint32_t size;


// Just to make sure
ClearBuffers();

Expand All @@ -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 );
Expand Down
48 changes: 17 additions & 31 deletions Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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<float>,
hsConstants::half_pi<float>,
Expand All @@ -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());
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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<float>)
{
if (rads >= hsConstants::pi<float>) {
// Recycle this one and restart the upper.
IShuffleDownGraphs(iPass);
}
else
{
} else {
float sinAge = hsFastMath::SinInRange(rads);

shader->SetVector(plGraphVS::kAmplitude,
Expand Down Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -81,6 +81,7 @@ class plAVIWriterImp : public plAVIWriter
void IFillBitmapInfo(BITMAPINFOHEADER* inf, plPipeline* pipeline);

bool ICaptureFrame(plPipeline* pipeline);
#endif

public:
plAVIWriterImp();
Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plGImage/plFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
5 changes: 3 additions & 2 deletions Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 1c4209c

Please sign in to comment.