[Fix] Fixed segmentation fault when system only has one planet with no factions.

This commit is contained in:
Allanis 2013-12-09 22:18:23 +00:00
parent 25660ff7d1
commit b7ddccd309
2 changed files with 16 additions and 17 deletions

View File

@ -186,29 +186,27 @@ static void map_update(void) {
/* System is known. */
window_modifyText(map_wid, "txtSysname", sys->name);
if(sys->nplanets == 0) { /* No planets -> no factions. */
standing = 0;
nstanding = 0;
for(i = 0; i < sys->nplanets; i++) {
if((f == -1) && (sys->planets[i]->faction > 0)) {
f = sys->planets[i]->faction;
standing += faction_getPlayer(f);
nstanding++;
}
else if(f != sys->planets[i]->faction && /* @todo More verbosity. */
(sys->planets[i]->faction > 0)) {
snprintf(buf, 100, "Multiple");
break;
}
}
if(f == -1) {
window_modifyText(map_wid, "txtFaction", "NA");
window_moveWidget(map_wid, "txtSStanding", -20, -100);
window_moveWidget(map_wid, "txtStanding", -20, -100-gl_smallFont.h-5);
window_modifyText(map_wid, "txtStanding", "NA");
y = -100;
} else {
standing = 0;
nstanding = 0;
f = -1;
for(i = 0; i < sys->nplanets; i++) {
if((f == -1) && (sys->planets[i]->faction > 0)) {
f = sys->planets[i]->faction;
standing += faction_getPlayer(f);
nstanding++;
}
else if(f != sys->planets[i]->faction &&
(sys->planets[i]->faction > 0)) {
/* @todo More verbosity. */
snprintf(buf, 100, "Multiple");
break;
}
}
if(i == sys->nplanets)
/* Saw them all, and all the same. */
snprintf(buf, 100, "%s", faction_longname(f));

View File

@ -615,6 +615,7 @@ static int planet_parse(Planet* planet, const xmlNodePtr parent) {
/* Clear up memory for sane defaults. */
memset(planet, 0, sizeof(Planet));
planet->faction = -1;
str[0] = '\0';
flags = 0;