From 489896d627c479fd2edac07361b7a3d043c2d584 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Mon, 21 Apr 2008 09:25:10 +0000 Subject: [PATCH] Make astarInner an `int` and ASSERT that it stays non-negative (i.e. that it doesn't overflow) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4725 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/astar.c | 4 +++- src/astar.h | 4 +++- src/fpath.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/astar.c b/src/astar.c index 4b7faf60c..41d93baa4 100644 --- a/src/astar.c +++ b/src/astar.c @@ -41,7 +41,7 @@ static SDWORD astarOuter, astarRemove; * * @ingroup pathfinding */ -SDWORD astarInner; +int astarInner = 0; // The structure to store a node of the route typedef struct _fp_node @@ -450,6 +450,8 @@ static FP_NODE *psNearest, *psRoute; } astarInner += 1; + ASSERT(astarInner >= 0, "astarInner overflowed!"); + // Now insert the point into the appropriate list if (!psFound) diff --git a/src/astar.h b/src/astar.h index b6ff5e952..147e146ed 100644 --- a/src/astar.h +++ b/src/astar.h @@ -51,9 +51,11 @@ typedef struct _astar_route } ASTAR_ROUTE; // counters for a-star -extern SDWORD astarInner; +extern int astarInner; /** Reset the A* counters + * + * This function resets astarInner among others. * * @ingroup pathfinding */ diff --git a/src/fpath.c b/src/fpath.c index e6104b6ea..72056491f 100644 --- a/src/fpath.c +++ b/src/fpath.c @@ -694,6 +694,8 @@ FPATH_RETVAL fpathRoute(DROID* psDroid, MOVE_CONTROL *psMoveCntl, fpathBlockingTile == fpathLiftBlockingTile, "fpathRoute: invalid blocking function" ); + ASSERT(astarInner >= 0, "astarInner overflowed!"); + if (astarInner > FPATH_LOOP_LIMIT) { // Time out