From 30cc5405aeaf8db1aef00718ce21f2b2decad9c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 4 Nov 2015 12:59:03 +0100 Subject: [PATCH] CID 22467: Division or modulo by zero github issue #348 --- src/names.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/names.c b/src/names.c index 71c4c6504..f608764d8 100644 --- a/src/names.c +++ b/src/names.c @@ -238,9 +238,6 @@ static const char *dragon_name(const unit * u) if (num_postfix == 0) num_postfix = -1; } - if (num_postfix <= 0) { - return NULL; - } if (u) { region *r = u->region; @@ -264,9 +261,16 @@ static const char *dragon_name(const unit * u) } } - rnd = num_postfix / 6; - rnd = (rng_int() % rnd) + ter * rnd; - + if (num_postfix <=0) { + return NULL; + } + else if (num_postfix < 6) { + rnd = rng_int() % num_postfix; + } + else { + rnd = num_postfix / 6; + rnd = (rng_int() % rnd) + ter * rnd; + } sprintf(zText, "dragon_postfix_%d", rnd); str = locale_getstring(default_locale, zText);