From c8c22aea1b02f43df7f03e5aa80e297575ab8c89 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Jan 2020 12:47:09 +0100 Subject: [PATCH] bug 2624: short range conversion bug in tree growth --- src/laws.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/laws.c b/src/laws.c index 4170975b5..53b49e1b6 100644 --- a/src/laws.c +++ b/src/laws.c @@ -594,6 +594,13 @@ growing_trees_e3(region * r, const int current_season, } } +static short cap_short(int i) { + if (i > SHRT_MIN) { + return ((i < SHRT_MAX) ? (short)i : SHRT_MAX); + } + return SHRT_MIN; +} + static void growing_trees(region * r, const season_t current_season, const season_t last_weeks_season) { @@ -687,8 +694,8 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee a = a_find(r->attribs, &at_germs); if (!a) { a = a_add(&r->attribs, a_new(&at_germs)); - a->data.sa[0] = (short)rtrees(r, 0); - a->data.sa[1] = (short)rtrees(r, 1); + a->data.sa[0] = cap_short(rtrees(r, 0)); + a->data.sa[1] = cap_short(rtrees(r, 1)); } /* wir haben 6 Wochen zum wachsen, jeder Same/Spross hat 18% Chance * zu wachsen, damit sollten nach 5-6 Wochen alle gewachsen sein */