From 1d811a613ffb926dd550654081d9a02423e395f0 Mon Sep 17 00:00:00 2001 From: Allanis Date: Mon, 10 Mar 2014 00:14:02 +0000 Subject: [PATCH] [Fix] On the rare occasion, accepting a mission has caused a segfault. This should sort it out. --- src/land.c | 4 ++-- src/mission.c | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/land.c b/src/land.c index dcca414..9244cc2 100644 --- a/src/land.c +++ b/src/land.c @@ -1040,7 +1040,7 @@ static void misn_accept(unsigned int wid, char* str) { misn = &mission_computer[pos]; if(mission_accept(misn)) { /* Success is accepting the mission. */ - memmove(misn, &mission_computer[pos+1], + memmove(&mission_computer[pos], &mission_computer[pos+1], sizeof(Mission) * (mission_ncomputer-pos-1)); mission_ncomputer--; misn_genList(wid, 0); @@ -1056,7 +1056,7 @@ static void misn_genList(unsigned int wid, int first) { window_destroyWidget(wid, "lstMission"); /* List. */ - if(mission_ncomputer != 0) { + if(mission_ncomputer > 0) { /* there are missions. */ misn_names = malloc(sizeof(char*) * mission_ncomputer); j = 0; diff --git a/src/mission.c b/src/mission.c index 9692ba1..e3bb90c 100644 --- a/src/mission.c +++ b/src/mission.c @@ -131,8 +131,13 @@ static int mission_init(Mission* mission, MissionData* misn, int load) { free(buf); /* Run create function. */ - if(load == 0) /* Never run when loading. */ - misn_run(mission, "create"); + if(load == 0) { /* Never run when loading. */ + /* Failed to create. */ + if(misn_run(mission, "create")) { + mission_cleanup(mission); + return -1; + } + } return mission->id; }