Prevent some infinite recursion
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5867 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
360dc86ef4
commit
fd0084951e
|
@ -75,7 +75,14 @@ static void dumpEOL(const DumpFileHandle file)
|
|||
|
||||
static void debug_exceptionhandler_data(void **, const char * const str)
|
||||
{
|
||||
ASSERT(str != NULL, "Empty string sent to debug callback");
|
||||
/* Can't use ASSERT here as that will cause us to be invoked again.
|
||||
* Possibly resulting in infinite recursion.
|
||||
*/
|
||||
assert(str != NULL && "Empty string sent to debug callback");
|
||||
|
||||
// For non-debug builds
|
||||
if (str == NULL)
|
||||
return;
|
||||
|
||||
// Push this message on the message list
|
||||
const char * last = &str[strlen(str)];
|
||||
|
|
|
@ -26,22 +26,25 @@
|
|||
#include "projectile.h"
|
||||
#include "structure.h"
|
||||
|
||||
void checkObject(const struct BASE_OBJECT* psObject, const char * const location_description, const char * function)
|
||||
void checkObject(const struct BASE_OBJECT* psObject, const char * const location_description, const char * function, const int recurse)
|
||||
{
|
||||
if (recurse < 0)
|
||||
return;
|
||||
|
||||
ASSERT(psObject != NULL, "NULL pointer");
|
||||
|
||||
switch (psObject->type)
|
||||
{
|
||||
case OBJ_DROID:
|
||||
checkDroid((const DROID *)psObject, location_description, function);
|
||||
checkDroid((const DROID *)psObject, location_description, function, recurse - 1);
|
||||
break;
|
||||
|
||||
case OBJ_STRUCTURE:
|
||||
checkStructure((const STRUCTURE *)psObject, location_description, function);
|
||||
checkStructure((const STRUCTURE *)psObject, location_description, function, recurse - 1);
|
||||
break;
|
||||
|
||||
case OBJ_PROJECTILE:
|
||||
checkProjectile((const PROJECTILE *)psObject, location_description, function);
|
||||
checkProjectile((const PROJECTILE *)psObject, location_description, function, recurse - 1);
|
||||
break;
|
||||
|
||||
case OBJ_FEATURE:
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
#ifndef __INCLUDED_BASEOBJECT_H__
|
||||
#define __INCLUDED_BASEOBJECT_H__
|
||||
|
||||
static const unsigned int max_check_object_recursion = 4;
|
||||
|
||||
// Forward declaration to allow pointers to this type
|
||||
struct BASE_OBJECT;
|
||||
|
||||
void checkObject(const struct BASE_OBJECT* psObject, const char * const location_description, const char * function);
|
||||
void checkObject(const struct BASE_OBJECT* psObject, const char * const location_description, const char * function, const int recurse);
|
||||
|
||||
/* assert if object is bad */
|
||||
#define CHECK_OBJECT(object) checkObject((object), AT_MACRO, __FUNCTION__)
|
||||
#define CHECK_OBJECT(object) checkObject((object), AT_MACRO, __FUNCTION__, max_check_object_recursion)
|
||||
|
||||
#endif // __INCLUDED_BASEOBJECT_H__
|
||||
|
|
|
@ -5171,10 +5171,13 @@ void droidSetPosition(DROID *psDroid, int x, int y)
|
|||
}
|
||||
|
||||
/** Check validity of a droid. Crash hard if it fails. */
|
||||
void checkDroid(const DROID *droid, const char * const location_description, const char * function)
|
||||
void checkDroid(const DROID *droid, const char * const location_description, const char * function, const int recurse)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (recurse < 0)
|
||||
return;
|
||||
|
||||
ASSERT_HELPER(droid != NULL, location_description, function, "CHECK_DROID: NULL pointer");
|
||||
ASSERT_HELPER(droid->type == OBJ_DROID, location_description, function, "CHECK_DROID: Not droid (type %d)", (int)droid->type);
|
||||
ASSERT_HELPER(droid->direction <= 360.0f && droid->direction >= 0.0f, location_description, function, "CHECK_DROID: Bad droid direction %f", droid->direction);
|
||||
|
|
|
@ -535,10 +535,10 @@ static inline void setSaveDroidBase(DROID *psSaveDroid, STRUCTURE *psNewBase)
|
|||
#endif
|
||||
}
|
||||
|
||||
void checkDroid(const DROID *droid, const char * const location_description, const char * function);
|
||||
void checkDroid(const DROID *droid, const char * const location_description, const char * function, const int recurse);
|
||||
|
||||
/* assert if droid is bad */
|
||||
#define CHECK_DROID(droid) checkDroid(droid, AT_MACRO, __FUNCTION__)
|
||||
#define CHECK_DROID(droid) checkDroid(droid, AT_MACRO, __FUNCTION__, max_check_object_recursion)
|
||||
|
||||
// Minimum damage a weapon will deal to its target
|
||||
#define MIN_WEAPON_DAMAGE 1
|
||||
|
|
|
@ -2249,8 +2249,11 @@ static UDWORD establishTargetHeight(BASE_OBJECT *psTarget)
|
|||
}
|
||||
}
|
||||
|
||||
void checkProjectile(const PROJECTILE* psProjectile, const char * const location_description, const char * function)
|
||||
void checkProjectile(const PROJECTILE* psProjectile, const char * const location_description, const char * function, const int recurse)
|
||||
{
|
||||
if (recurse < 0)
|
||||
return;
|
||||
|
||||
ASSERT_HELPER(psProjectile != NULL, location_description, function, "CHECK_PROJECTILE: NULL pointer");
|
||||
ASSERT_HELPER(psProjectile->psWStats != NULL, location_description, function, "CHECK_PROJECTILE");
|
||||
ASSERT_HELPER(psProjectile->type == OBJ_PROJECTILE, location_description, function, "CHECK_PROJECTILE");
|
||||
|
@ -2261,11 +2264,11 @@ void checkProjectile(const PROJECTILE* psProjectile, const char * const location
|
|||
ASSERT_HELPER(psProjectile->direction <= 360.0f && psProjectile->direction >= 0.0f, location_description, function, "CHECK_PROJECTILE: out of range direction (%f)", psProjectile->direction);
|
||||
|
||||
if (psProjectile->psDest)
|
||||
checkObject(psProjectile->psDest, location_description, function);
|
||||
checkObject(psProjectile->psDest, location_description, function, recurse - 1);
|
||||
|
||||
if (psProjectile->psSource)
|
||||
checkObject(psProjectile->psSource, location_description, function);
|
||||
checkObject(psProjectile->psSource, location_description, function, recurse - 1);
|
||||
|
||||
if (psProjectile->psDamaged)
|
||||
checkObject(psProjectile->psDamaged, location_description, function);
|
||||
checkObject(psProjectile->psDamaged, location_description, function, recurse - 1);
|
||||
}
|
||||
|
|
|
@ -97,9 +97,9 @@ static inline void setProjectileDamaged(PROJECTILE *psProj, BASE_OBJECT *psObj)
|
|||
|
||||
/* @} */
|
||||
|
||||
void checkProjectile(const PROJECTILE* psProjectile, const char * const location_description, const char * function);
|
||||
void checkProjectile(const PROJECTILE* psProjectile, const char * const location_description, const char * function, const int recurse);
|
||||
|
||||
/* assert if projectile is bad */
|
||||
#define CHECK_PROJECTILE(object) checkProjectile((object), AT_MACRO, __FUNCTION__)
|
||||
#define CHECK_PROJECTILE(object) checkProjectile((object), AT_MACRO, __FUNCTION__, max_check_object_recursion)
|
||||
|
||||
#endif // __INCLUDED_SRC_PROJECTILE_H__
|
||||
|
|
|
@ -7953,10 +7953,13 @@ BOOL structureCheckReferences(STRUCTURE *psVictimStruct)
|
|||
return true;
|
||||
}
|
||||
|
||||
void checkStructure(const STRUCTURE* psStructure, const char * const location_description, const char * function)
|
||||
void checkStructure(const STRUCTURE* psStructure, const char * const location_description, const char * function, const int recurse)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (recurse < 0)
|
||||
return;
|
||||
|
||||
ASSERT(psStructure != NULL, location_description, function, "CHECK_STRUCTURE: NULL pointer");
|
||||
ASSERT(psStructure->type == OBJ_STRUCTURE, location_description, function, "CHECK_STRUCTURE: No structure (type num %u)", function, (unsigned int)psStructure->type);
|
||||
ASSERT(psStructure->player < MAX_PLAYERS, location_description, function, "CHECK_STRUCTURE: Out of bound player num (%u)", (unsigned int)psStructure->player);
|
||||
|
@ -7968,7 +7971,7 @@ void checkStructure(const STRUCTURE* psStructure, const char * const location_de
|
|||
ASSERT(psStructure->turretRotation[i] <= 360, location_description, function, "CHECK_STRUCTURE: Out of range turret rotation (turret %u; rotation: %u)", i, (unsigned int)psStructure->turretRotation[i]);
|
||||
if (psStructure->psTarget[i])
|
||||
{
|
||||
checkObject(psStructure->psTarget[i], location_description, function);
|
||||
checkObject(psStructure->psTarget[i], location_description, function, recurse - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,9 +441,9 @@ static inline void _setStructureTarget(STRUCTURE *psBuilding, BASE_OBJECT *psNew
|
|||
#endif
|
||||
}
|
||||
|
||||
void checkStructure(const STRUCTURE* psStructure, const char * const location_description, const char * function);
|
||||
void checkStructure(const STRUCTURE* psStructure, const char * const location_description, const char * function, const int recurse);
|
||||
|
||||
#define CHECK_STRUCTURE(object) checkStructure((object), AT_MACRO, __FUNCTION__)
|
||||
#define CHECK_STRUCTURE(object) checkStructure((object), AT_MACRO, __FUNCTION__, max_check_object_recursion)
|
||||
|
||||
extern void structureInitVars(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue