Skip to content

Commit

Permalink
Assert that indexes are on board
Browse files Browse the repository at this point in the history
  • Loading branch information
AI0867 authored and GregoryLundberg committed Nov 30, 2017
1 parent 41bc43a commit 53c7723
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/pathfind/pathfind.cpp
Expand Up @@ -194,12 +194,11 @@ namespace {

// Constructor:
findroute_indexer(int a, int b) : w(a), h(b) { }
// Convert to an index: (returns -1 on out of bounds)
// Convert to an index: (throws on out of bounds)
int operator()(int x, int y) const {
if ( x < 0 || w <= x || y < 0 || h <= y )
return -1;
else
return x + y*w;
VALIDATE(this->on_board(x,y),
"Pathfind: Location not on board");
return x + y*w;
}
int operator()(const map_location& loc) const {
return (*this)(loc.x, loc.y);
Expand Down

0 comments on commit 53c7723

Please sign in to comment.