Browse Source

Merge pull request #404 from dpogue/coverity

Coverity
Adam Johnson 11 years ago
parent
commit
683945fb7d
  1. 18
      Sources/Plasma/CoreLib/HeadSpin.cpp
  2. 20
      Sources/Plasma/CoreLib/HeadSpin.h
  3. 32
      Sources/Plasma/CoreLib/hsBounds.cpp
  4. 12
      Sources/Plasma/CoreLib/hsFastMath.h
  5. 4
      Sources/Plasma/CoreLib/plFileSystem.cpp

18
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -80,7 +80,7 @@ hsDebugMessageProc hsSetDebugMessageProc(hsDebugMessageProc newProc)
} }
#ifdef HS_DEBUGGING #ifdef HS_DEBUGGING
void hsDebugMessage (const char message[], long val) void hsDebugMessage (const char* message, long val)
{ {
char s[1024]; char s[1024];
@ -112,7 +112,7 @@ void ErrorEnableGui(bool enabled)
s_GuiAsserts = enabled; s_GuiAsserts = enabled;
} }
void ErrorAssert(int line, const char file[], const char fmt[], ...) void ErrorAssert(int line, const char* file, const char* fmt, ...)
{ {
#if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE) #if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
char msg[1024]; char msg[1024];
@ -158,7 +158,7 @@ void DebugBreakIfDebuggerPresent()
#endif // _MSC_VER #endif // _MSC_VER
} }
void DebugMsg(const char fmt[], ...) void DebugMsg(const char* fmt, ...)
{ {
char msg[1024]; char msg[1024];
va_list args; va_list args;
@ -180,7 +180,7 @@ void DebugMsg(const char fmt[], ...)
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
void hsStatusMessage(const char message[]) void hsStatusMessage(const char* message)
{ {
if (gHSStatusProc) { if (gHSStatusProc) {
gHSStatusProc(message); gHSStatusProc(message);
@ -243,7 +243,7 @@ public:
bool hsMessageBox_SuppressPrompts = false; bool hsMessageBox_SuppressPrompts = false;
int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon) int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon)
{ {
if (hsMessageBox_SuppressPrompts) if (hsMessageBox_SuppressPrompts)
return hsMBoxOk; return hsMBoxOk;
@ -296,7 +296,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char c
return hsMBoxCancel; return hsMBoxCancel;
} }
int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon) int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon)
{ {
if (hsMessageBox_SuppressPrompts) if (hsMessageBox_SuppressPrompts)
return hsMBoxOk; return hsMBoxOk;
@ -349,18 +349,18 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wch
return hsMBoxCancel; return hsMBoxCancel;
} }
int hsMessageBox(const char message[], const char caption[], int kind, int icon) int hsMessageBox(const char* message, const char* caption, int kind, int icon)
{ {
return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon);
} }
int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon) int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon)
{ {
return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon);
} }
/**************************************/ /**************************************/
char* hsStrcpy(char dst[], const char src[]) char* hsStrcpy(char* dst, const char* src)
{ {
if (src) if (src)
{ {

20
Sources/Plasma/CoreLib/HeadSpin.h

@ -332,14 +332,14 @@ void SWAP (T & a, T & b) {
# define hsStatusMessage(x) NULL_STMT # define hsStatusMessage(x) NULL_STMT
# define hsStatusMessageF(x, ...) NULL_STMT # define hsStatusMessageF(x, ...) NULL_STMT
#else #else
void hsStatusMessage(const char message[]); void hsStatusMessage(const char* message);
void hsStatusMessageF(const char * fmt, ...); void hsStatusMessageF(const char * fmt, ...);
#endif // PLASMA_EXTERNAL_RELEASE #endif // PLASMA_EXTERNAL_RELEASE
char* hsStrcpy(char dstOrNil[], const char src[]); char* hsStrcpy(char* dstOrNil, const char* src);
void hsStrLower(char *s); void hsStrLower(char *s);
inline char* hsStrcpy(const char src[]) inline char* hsStrcpy(const char* src)
{ {
return hsStrcpy(nil, src); return hsStrcpy(nil, src);
} }
@ -381,10 +381,10 @@ enum { // RETURN VALUES FROM hsMessageBox
}; };
extern bool hsMessageBox_SuppressPrompts; extern bool hsMessageBox_SuppressPrompts;
int hsMessageBox(const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBox(const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk);
int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk);
int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk);
int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk);
// flag testing / clearing // flag testing / clearing
#define hsCheckBits(f,c) ((f & c)==c) #define hsCheckBits(f,c) ((f & c)==c)
@ -449,15 +449,15 @@ extern hsDebugMessageProc gHSStatusProc;
hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc);
void ErrorEnableGui (bool enabled); void ErrorEnableGui (bool enabled);
void ErrorAssert (int line, const char file[], const char fmt[], ...); void ErrorAssert (int line, const char* file, const char* fmt, ...);
bool DebugIsDebuggerPresent (); bool DebugIsDebuggerPresent ();
void DebugBreakIfDebuggerPresent (); void DebugBreakIfDebuggerPresent ();
void DebugMsg(const char fmt[], ...); void DebugMsg(const char* fmt, ...);
#ifdef HS_DEBUGGING #ifdef HS_DEBUGGING
void hsDebugMessage(const char message[], long refcon); void hsDebugMessage(const char* message, long refcon);
#define hsDebugCode(code) code #define hsDebugCode(code) code
#define hsIfDebugMessage(expr, msg, ref) (void)( ((expr) != 0) || (hsDebugMessage(msg, ref), 0) ) #define hsIfDebugMessage(expr, msg, ref) (void)( ((expr) != 0) || (hsDebugMessage(msg, ref), 0) )
#define hsAssert(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) ) #define hsAssert(expr, msg) (void)( ((expr) != 0) || (ErrorAssert(__LINE__, __FILE__, msg), 0) )

32
Sources/Plasma/CoreLib/hsBounds.cpp

@ -2208,9 +2208,11 @@ bool hsBounds3Ext::ISectBoxBS(const hsBounds3Ext &other, const hsVector3 &myVel,
hsVector3 tstAxis; hsVector3 tstAxis;
float tstDepth; float tstDepth;
int i; int i;
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
bool tryAxis; bool tryAxis = false;
if( other.fExtFlags & kAxisAligned ) if( other.fExtFlags & kAxisAligned )
{ {
// first try the other box axes // first try the other box axes
@ -2223,31 +2225,28 @@ bool hsBounds3Ext::ISectBoxBS(const hsBounds3Ext &other, const hsVector3 &myVel,
effMin += velDist; effMin += velDist;
effMax += fRadius; effMax += fRadius;
effMin -= fRadius; effMin -= fRadius;
if( effMax < other.fMins[i] ) if( effMax < other.fMins[i] )
return false; return false;
if( effMin > other.fMaxs[i] ) if( effMin > other.fMaxs[i] )
return false; return false;
if( (other.fMins[i] <= effMin) if ((other.fMins[i] <= effMin) &&
&&(other.fMaxs[i] <= effMax) ) (other.fMaxs[i] <= effMax))
{ {
tstDepth = other.fMaxs[i] - effMin; tstDepth = other.fMaxs[i] - effMin;
hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis"); hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis");
tstAxis.Set(i == 0 ? 1.f : 0, i & 1 ? 1.f : 0, i & 2 ? 1.f : 0); tstAxis.Set(i == 0 ? 1.f : 0, i & 1 ? 1.f : 0, i & 2 ? 1.f : 0);
tryAxis = true; tryAxis = true;
} }
else else if ((other.fMins[i] >= effMin) &&
if( (other.fMins[i] >= effMin) (other.fMaxs[i] >= effMax))
&&(other.fMaxs[i] >= effMax) )
{ {
tstDepth = effMax - other.fMins[i]; tstDepth = effMax - other.fMins[i];
hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis"); hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis");
tstAxis.Set(i == 0 ? -1.f : 0, i & 1 ? -1.f : 0, i & 2 ? -1.f : 0); tstAxis.Set(i == 0 ? -1.f : 0, i & 1 ? -1.f : 0, i & 2 ? -1.f : 0);
tryAxis = true; tryAxis = true;
} }
else
tryAxis = false;
} }
else else
{ {
@ -2263,7 +2262,7 @@ bool hsBounds3Ext::ISectBoxBS(const hsBounds3Ext &other, const hsVector3 &myVel,
effMin += velDist; effMin += velDist;
effMax += radScaled; effMax += radScaled;
effMin -= radScaled; effMin -= radScaled;
if( !(other.fExtFlags & kDistsSet) ) if( !(other.fExtFlags & kDistsSet) )
other.IMakeDists(); other.IMakeDists();
@ -2271,24 +2270,21 @@ bool hsBounds3Ext::ISectBoxBS(const hsBounds3Ext &other, const hsVector3 &myVel,
return false; return false;
if( effMin > other.fDists[i].fY ) if( effMin > other.fDists[i].fY )
return false; return false;
if( centerDist <= other.fDists[i].fX ) if (centerDist <= other.fDists[i].fX)
{ {
tstDepth = effMax - other.fDists[i].fX; tstDepth = effMax - other.fDists[i].fX;
tstAxis = -other.fAxes[i]; tstAxis = -other.fAxes[i];
hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis"); hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis");
} }
else else if (centerDist >= other.fDists[i].fY)
if( centerDist >= other.fDists[i].fY )
{ {
tstDepth = other.fDists[i].fY - effMin; tstDepth = other.fDists[i].fY - effMin;
tstAxis = other.fAxes[i]; tstAxis = other.fAxes[i];
hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis"); hsAssert(tstDepth > -kRealSmall, "Late to be finding sep axis");
} }
else
tryAxis = false;
} }
if( tryAxis ) if( tryAxis )
{ {
float magSq = tstAxis.MagnitudeSquared(); float magSq = tstAxis.MagnitudeSquared();

12
Sources/Plasma/CoreLib/hsFastMath.h

@ -106,13 +106,13 @@ public:
inline float hsFastMath::InvSqrtAppr(float x) inline float hsFastMath::InvSqrtAppr(float x)
{ {
register unsigned long a = *(long*)&x; unsigned long a = *(long*)&x;
register float arg = x; float arg = x;
union { union {
long i; long i;
float f; float f;
} seed; } seed;
register float r; float r;
extern unsigned char statSeedTable[]; extern unsigned char statSeedTable[];
@ -133,13 +133,13 @@ inline float hsFastMath::InvSqrtAppr(float x)
inline float hsFastMath::InvSqrt(float x) inline float hsFastMath::InvSqrt(float x)
{ {
register unsigned long a = *(long*)&x; unsigned long a = *(long*)&x;
register float arg = x; float arg = x;
union { union {
long i; long i;
float f; float f;
} seed; } seed;
register float r; float r;
extern unsigned char statSeedTable[]; extern unsigned char statSeedTable[];

4
Sources/Plasma/CoreLib/plFileSystem.cpp

@ -209,11 +209,11 @@ plFileInfo::plFileInfo(const plFileName &filename)
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
struct __stat64 info; struct __stat64 info;
if (!_wstat64(filename.AsString().ToWchar(), &info) == 0) if (_wstat64(filename.AsString().ToWchar(), &info) != 0)
return; return;
#else #else
struct stat info; struct stat info;
if (!stat(filename.AsString().c_str(), &info) == 0) if (stat(filename.AsString().c_str(), &info) != 0)
return; return;
#endif #endif

Loading…
Cancel
Save