CID 22467: Division or modulo by zero

github issue #348
This commit is contained in:
Enno Rehling 2015-11-04 12:59:03 +01:00
parent 05ff554053
commit 30cc5405ae
1 changed files with 10 additions and 6 deletions

View File

@ -238,9 +238,6 @@ static const char *dragon_name(const unit * u)
if (num_postfix == 0) if (num_postfix == 0)
num_postfix = -1; num_postfix = -1;
} }
if (num_postfix <= 0) {
return NULL;
}
if (u) { if (u) {
region *r = u->region; region *r = u->region;
@ -264,9 +261,16 @@ static const char *dragon_name(const unit * u)
} }
} }
rnd = num_postfix / 6; if (num_postfix <=0) {
rnd = (rng_int() % rnd) + ter * rnd; 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); sprintf(zText, "dragon_postfix_%d", rnd);
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);