Skip to content

Commit

Permalink
Fixed a missing bounds check (crash)
Browse files Browse the repository at this point in the history
Fixed a missing array bounds check that was causing a UI crash under
certain conditions.
  • Loading branch information
mcgrew committed Jul 27, 2019
1 parent 4ee25a3 commit 1187c2b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions common/map.c
Expand Up @@ -271,13 +271,12 @@ static inline BOOL needs_bridge(uint8_t left, uint8_t right)
/**
* Adds bridges where necessary to connect continents
* @param map The map struct
* @param lm_sizes The sizes of all land masses on the map.
* @return A boolean indicating if a bridge was placed.
*/
static BOOL add_bridges(dw_map *map)
{
/* this could use more work */
uint8_t x, y, left, right, x_candidate[50], y_candidate[50];
uint8_t x, y, left, right, x_candidate[120], y_candidate[120];
uint64_t which;
int count = 0;
dw_tile tile;
Expand All @@ -293,8 +292,13 @@ static BOOL add_bridges(dw_map *map)
y_candidate[count++] = y;
}
}
if (count >= 120) {
printf("Maximum bridge candidates reached\n");
goto max_candidates;
}
}
}
max_candidates:
if (count) {
which = mt_rand(0, count-1);
x = x_candidate[which];
Expand Down

0 comments on commit 1187c2b

Please sign in to comment.