[Change] Avoid a theoretical infinite loop plus a memleak in the map.
This commit is contained in:
parent
14fc795816
commit
fbc7169d21
@ -365,7 +365,7 @@
|
||||
<energy_regen>125</energy_regen>
|
||||
</specific>
|
||||
</outfit>
|
||||
<outfit name="Shield Capacitator">
|
||||
<outfit name="Shield Capacitor">
|
||||
<general>
|
||||
<max>12</max>
|
||||
<tech>9</tech>
|
||||
|
18
src/map.c
18
src/map.c
@ -21,6 +21,9 @@
|
||||
#define BUTTON_WIDTH 60 /**< Map button width. */
|
||||
#define BUTTON_HEIGHT 30 /**< Map button height. */
|
||||
|
||||
#define MAP_LOOP_PROT 250 /**< Number of iterations max in pathfinding before
|
||||
aborting. */
|
||||
|
||||
static double map_zoom = 1.; /**< Zoom of the map. */
|
||||
static double map_xpos = 0.; /**< Map X position. */
|
||||
static double map_ypos = 0.; /**< Map Y position. */
|
||||
@ -766,7 +769,7 @@ static void A_freeList(SysNode* first) {
|
||||
}
|
||||
|
||||
StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known) {
|
||||
int i, cost;
|
||||
int i, j, cost;
|
||||
|
||||
StarSystem* sys, *ssys, *esys, **res;
|
||||
|
||||
@ -792,7 +795,13 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
|
||||
cur = A_newNode(ssys, NULL);
|
||||
open = A_add(open, cur); /* Initial open node is the start system. */
|
||||
|
||||
j = 0;
|
||||
while((cur = A_lowest(open))->sys != esys) {
|
||||
/* Break if infinite loop. */
|
||||
j++;
|
||||
if(j > MAP_LOOP_PROT)
|
||||
break;
|
||||
|
||||
/* Get best from open and toss to closed. */
|
||||
open = A_rm(open, cur->sys);
|
||||
closed = A_add(closed, cur);
|
||||
@ -825,13 +834,18 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Build the path backwards. */
|
||||
/* Build the path backwards if not broken from loop. */
|
||||
if(j <= MAP_LOOP_PROT) {
|
||||
(*njumps) = A_g(cur);
|
||||
res = malloc(sizeof(StarSystem*) * (*njumps));
|
||||
for(i = 0; i < (*njumps); i++) {
|
||||
res[(*njumps)-i-1] = cur->sys;
|
||||
cur = cur->parent;
|
||||
}
|
||||
} else {
|
||||
(*njumps) = 0;
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
/* Free the linked list. */
|
||||
A_freeList(A_gc);
|
||||
|
Loading…
Reference in New Issue
Block a user