From f18b5ea7d27d1ba1b520520400e132821b5206ff Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Sun, 1 Nov 2015 18:54:29 +0100 Subject: [PATCH 1/4] general check for sf->faction's validity The handling of an ally without a valid faction-pointer is now skipped in favor of a logged error. --- src/kernel/save.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 300555180..b70583fc8 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1346,11 +1346,16 @@ void writefaction(struct gamedata *data, const faction * f) WRITE_SECTION(data->store); for (sf = f->allies; sf; sf = sf->next) { - int no = (sf->faction != NULL) ? sf->faction->no : 0; - int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); - if (status != 0) { - WRITE_INT(data->store, no); - WRITE_INT(data->store, sf->status); + if (sf->faction != NULL) { + int no = sf->faction->no; + int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); + if (status != 0) { + WRITE_INT(data->store, no); + WRITE_INT(data->store, sf->status); + } + } + else { + log_error("NULL-pointer in ally-struct for faction '%s'.", f->no); } } WRITE_INT(data->store, 0); From 491e5faed9b6d40bb7ab727aed07cb1a22c6b8bc Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Sun, 1 Nov 2015 21:40:06 +0100 Subject: [PATCH 2/4] Revert "general check for sf->faction's validity" This reverts commit f18b5ea7d27d1ba1b520520400e132821b5206ff. --- src/kernel/save.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index b70583fc8..300555180 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1346,16 +1346,11 @@ void writefaction(struct gamedata *data, const faction * f) WRITE_SECTION(data->store); for (sf = f->allies; sf; sf = sf->next) { - if (sf->faction != NULL) { - int no = sf->faction->no; - int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); - if (status != 0) { - WRITE_INT(data->store, no); - WRITE_INT(data->store, sf->status); - } - } - else { - log_error("NULL-pointer in ally-struct for faction '%s'.", f->no); + int no = (sf->faction != NULL) ? sf->faction->no : 0; + int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); + if (status != 0) { + WRITE_INT(data->store, no); + WRITE_INT(data->store, sf->status); } } WRITE_INT(data->store, 0); From b107ddadf590a1ac2403022b7b8919bcdb324def Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Sun, 1 Nov 2015 21:43:18 +0100 Subject: [PATCH 3/4] added assert to check the faction-pointer --- src/kernel/save.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 300555180..511585dda 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1346,7 +1346,9 @@ void writefaction(struct gamedata *data, const faction * f) WRITE_SECTION(data->store); for (sf = f->allies; sf; sf = sf->next) { - int no = (sf->faction != NULL) ? sf->faction->no : 0; + assert(sf->faction); + + int no = sf->faction->no; int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); if (status != 0) { WRITE_INT(data->store, no); From 07fd3dc970451eaf0182eb26b48798d4b21115d7 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 18:06:19 +0100 Subject: [PATCH 4/4] formal correction --- src/kernel/save.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 511585dda..b3c38d686 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1346,10 +1346,14 @@ void writefaction(struct gamedata *data, const faction * f) WRITE_SECTION(data->store); for (sf = f->allies; sf; sf = sf->next) { + int no; + int status; + assert(sf->faction); - int no = sf->faction->no; - int status = alliedfaction(NULL, f, sf->faction, HELP_ALL); + no = sf->faction->no; + status = alliedfaction(NULL, f, sf->faction, HELP_ALL); + if (status != 0) { WRITE_INT(data->store, no); WRITE_INT(data->store, sf->status);