From a5f056b4b6ef8461b042dec79374efef5ad68134 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 14:01:37 +0200 Subject: [PATCH 1/3] re-enable an assertion that was commented out. fix a size_t range warning, change error code for wrptr(). --- src/laws.test.c | 2 +- src/util/bsdstring.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 987b27773..58cba3942 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -700,7 +700,7 @@ static void statistic_test(CuTest *tc, int peasants, int luck, int maxp, for (i = 0; i < 1000; ++i) { effect = peasant_luck_effect(peasants, luck, maxp, variance); CuAssertTrue(tc, min_value <= effect); -// broken CuAssertTrue(tc, max_value >= effect); + CuAssertTrue(tc, max_value >= effect); } } diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index c43847da1..4205b9480 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes) if (bytes == 0) { return 0; } - if (bytes < 0) { - *size = 0; - return EINVAL; - } if (bytes <= *size) { *ptr += bytes; *size -= bytes; @@ -24,7 +20,7 @@ int wrptr(char **ptr, size_t * size, size_t bytes) *ptr += *size; *size = 0; - return ENAMETOOLONG; + return ERANGE; } #ifndef HAVE_STRLCPY From 69821b2a324d9af844002f8bcdce5861d7542a1b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 May 2015 17:29:01 +0200 Subject: [PATCH 2/3] cleanup battle.h header removed some unreferenced functions from battle.h, made them static in battle.c --- src/battle.c | 40 ++++++++++++++++++++-------------------- src/battle.h | 7 ++----- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/battle.c b/src/battle.c index ee9465602..db2dbc3ca 100644 --- a/src/battle.c +++ b/src/battle.c @@ -431,7 +431,7 @@ static int get_row(const side * s, int row, const side * vs) return result; } -int get_unitrow(const fighter * af, const side * vs) +static int get_unitrow(const fighter * af, const side * vs) { int row = statusrow(af->status); if (vs == NULL) { @@ -3661,6 +3661,24 @@ static void free_fighter(fighter * fig) } +static void battle_free(battle * b) { + side *s; + + assert(b); + + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fnext = s->fighters; + while (fnext) { + fighter *fig = fnext; + fnext = fig->next; + free_fighter(fig); + free(fig); + } + free_side(s); + } + free(b); +} + void free_battle(battle * b) { int max_fac_no = 0; @@ -3740,7 +3758,7 @@ static int battle_report(battle * b) char buffer[32]; if (komma) { - bytes = strlcpy(bufp, ", ", size); + strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -4295,21 +4313,3 @@ void do_battle(region * r) } } -void battle_free(battle * b) { - side *s; - - assert(b); - - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fnext = s->fighters; - while (fnext) { - fighter *fig = fnext; - fnext = fig->next; - free_fighter(fig); - free(fig); - } - free_side(s); - } - free(b); -} - diff --git a/src/battle.h b/src/battle.h index 9bf500ed9..075edf496 100644 --- a/src/battle.h +++ b/src/battle.h @@ -225,8 +225,6 @@ extern "C" { extern const troop no_troop; /* BEGIN battle interface */ - void battle_init(battle * b); - void battle_free(battle * b); side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); side * get_side(battle * b, const struct unit * u); fighter * get_fighter(battle * b, const struct unit * u); @@ -251,11 +249,10 @@ extern "C" { extern int hits(troop at, troop dt, weapon * awp); extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); - extern struct quicklist *fighters(struct battle *b, const struct side *vs, + struct quicklist *fighters(struct battle *b, const struct side *vs, int minrow, int maxrow, int mask); - extern int count_allies(const struct side *as, int minrow, int maxrow, + int count_allies(const struct side *as, int minrow, int maxrow, int select, int allytype); - extern int get_unitrow(const struct fighter *af, const struct side *vs); extern bool helping(const struct side *as, const struct side *ds); extern void rmfighter(fighter * df, int i); extern struct fighter *select_corpse(struct battle *b, struct fighter *af); From 689519565973bbc94b6bc4d22e5a733d93e5d58c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Jun 2015 19:56:53 +0200 Subject: [PATCH 3/3] gmtool makes invalid regions (github issue #198). forgot to null a pointer after freeing it. --- src/kernel/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 3656c8ef1..24c11a0dd 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -956,8 +956,10 @@ void setluxuries(region * r, const luxury_type * sale) assert(r->land); - if (r->land->demands) + if (r->land->demands) { freelist(r->land->demands); + r->land->demands = 0; + } for (ltype = luxurytypes; ltype; ltype = ltype->next) { struct demand *dmd = malloc(sizeof(struct demand));