CID 22463 Division or modulo by zero

This commit is contained in:
Enno Rehling 2015-11-03 23:13:04 +01:00
parent fff40f048b
commit 876e4122b1
1 changed files with 5 additions and 3 deletions

View File

@ -593,10 +593,12 @@ int skill_limit(faction * f, skill_t sk)
if (sk != SK_ALCHEMY && sk != SK_MAGIC)
return INT_MAX;
if (f_get_alliance(f)) {
int ac = listlen(f->alliance->members); /* number of factions */
int fl = (al + ac - 1) / ac; /* faction limit, rounded up */
int sc, fl, ac = listlen(f->alliance->members); /* number of factions */
assert(ac > 0);
fl = (al + ac - 1) / ac; /* faction limit, rounded up */
/* the faction limit may not be achievable because it would break the alliance-limit */
int sc = al - allied_skillcount(f, sk);
sc = al - allied_skillcount(f, sk);
if (sc <= 0)
return 0;
return fl;