From 3d7b22fa219a4be4c7e808f9ddeef054281863c7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Jan 2016 14:31:24 +0100 Subject: [PATCH 1/4] avoid crashing because of bug 2182 --- src/kernel/save.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 29439986a..1c78615a7 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -944,15 +944,19 @@ static region *readregion(struct gamedata *data, int x, int y) READ_INT(data->store, &n); rsetherbs(r, (short)n); READ_INT(data->store, &n); - rsetpeasants(r, n); + if (n < 0) { + /* bug 2182 */ + log_error("data has negative peasants: %d in %s", n, regionname(r, 0)); + rsetpeasants(r, 0); + } + else { + rsetpeasants(r, n); + } READ_INT(data->store, &n); rsetmoney(r, n); } assert(r->terrain != NULL); - assert(rhorses(r) >= 0); - assert(rpeasants(r) >= 0); - assert(rmoney(r) >= 0); if (r->land) { int n; From 023686fab2b587436ee38c9533900c5ebfc9a817 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Jan 2016 14:35:46 +0100 Subject: [PATCH 2/4] add a liberal sprinkling of assertions to catch negative peasants bug 2182 --- src/kernel/region.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 779b45e4a..01ec02375 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -595,14 +595,19 @@ bool is_coastregion(region * r) int rpeasants(const region * r) { - return ((r)->land ? (r)->land->peasants : 0); + int value = 0; + if (r->land) { + value = r->land->peasants; + assert(value >= 0); + } + return value; } void rsetpeasants(region * r, int value) { - if (r->land) r->land->peasants = value; - else assert(value>=0); - + assert(r->land); + assert(value >= 0); + r->land->peasants = value; } int rmoney(const region * r) From a6b15813edc8e636ce00a89485a2b37c357aebb2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Jan 2016 14:45:46 +0100 Subject: [PATCH 3/4] relax strict assertion (should be allowed to set ocean to 0 peasants) --- src/kernel/region.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 01ec02375..d12f72389 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -605,9 +605,10 @@ int rpeasants(const region * r) void rsetpeasants(region * r, int value) { - assert(r->land); assert(value >= 0); - r->land->peasants = value; + if (r->land) { + r->land->peasants = value; + } } int rmoney(const region * r) @@ -617,9 +618,11 @@ int rmoney(const region * r) void rsethorses(const region * r, int value) { + assert(r->land || value==0); assert(value >= 0); - if (r->land) + if (r->land) { r->land->horses = value; + } } int rhorses(const region * r) From 5072d5963676a865f7ef73fc436566bd43c61f62 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Jan 2016 14:51:52 +0100 Subject: [PATCH 4/4] release version 3.7.9 --- src/buildno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildno.h b/src/buildno.h index 1e81528c2..bd1984af2 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 7 -#define VERSION_BUILD 8 +#define VERSION_BUILD 9