forked from github/server
CID 22465 Division or modulo by zero
This commit is contained in:
parent
a02b5f343e
commit
978dd1400f
1 changed files with 17 additions and 16 deletions
33
src/battle.c
33
src/battle.c
|
@ -300,9 +300,8 @@ fighter *select_corpse(battle * b, fighter * af)
|
||||||
*
|
*
|
||||||
* Untote werden nicht ausgewählt (casualties, not dead) */
|
* Untote werden nicht ausgewählt (casualties, not dead) */
|
||||||
{
|
{
|
||||||
int si, di, maxcasualties = 0;
|
int si, maxcasualties = 0;
|
||||||
fighter *df;
|
fighter *df;
|
||||||
side *s;
|
|
||||||
|
|
||||||
for (si = 0; si != b->nsides; ++si) {
|
for (si = 0; si != b->nsides; ++si) {
|
||||||
side *s = b->sides + si;
|
side *s = b->sides + si;
|
||||||
|
@ -310,24 +309,26 @@ fighter *select_corpse(battle * b, fighter * af)
|
||||||
maxcasualties += s->casualties;
|
maxcasualties += s->casualties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
di = (int)(rng_int() % maxcasualties);
|
if (maxcasualties > 0) {
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
int di = (int)(rng_int() % maxcasualties);
|
||||||
for (df = s->fighters; df; df = df->next) {
|
side *s;
|
||||||
/* Geflohene haben auch 0 hp, dürfen hier aber nicht ausgewählt
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
* werden! */
|
for (df = s->fighters; df; df = df->next) {
|
||||||
int dead = dead_fighters(df);
|
/* Geflohene haben auch 0 hp, dürfen hier aber nicht ausgewählt
|
||||||
if (!playerrace(u_race(df->unit)))
|
* werden! */
|
||||||
continue;
|
int dead = dead_fighters(df);
|
||||||
|
if (!playerrace(u_race(df->unit)))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (af && !helping(af->side, df->side))
|
if (af && !helping(af->side, df->side))
|
||||||
continue;
|
continue;
|
||||||
if (di < dead) {
|
if (di < dead) {
|
||||||
return df;
|
return df;
|
||||||
|
}
|
||||||
|
di -= dead;
|
||||||
}
|
}
|
||||||
di -= dead;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue