From b7ddccd3092ded8b4a3b232245108213c8ccb10e Mon Sep 17 00:00:00 2001 From: Allanis <allanis@saracraft.net> Date: Mon, 9 Dec 2013 22:18:23 +0000 Subject: [PATCH] [Fix] Fixed segmentation fault when system only has one planet with no factions. --- src/map.c | 32 +++++++++++++++----------------- src/space.c | 1 + 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/map.c b/src/map.c index 7eb8600..1b1d08a 100644 --- a/src/map.c +++ b/src/map.c @@ -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)); diff --git a/src/space.c b/src/space.c index 3b5b47c..f00e99e 100644 --- a/src/space.c +++ b/src/space.c @@ -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;