forked from github/server
avoid code analysis warnings
This commit is contained in:
parent
d2389fa87b
commit
aa466f3cc8
4 changed files with 39 additions and 19 deletions
|
@ -67,6 +67,7 @@ void new_potiontype(item_type * itype, int level)
|
||||||
potion_type *ptype;
|
potion_type *ptype;
|
||||||
|
|
||||||
ptype = (potion_type *)calloc(1, sizeof(potion_type));
|
ptype = (potion_type *)calloc(1, sizeof(potion_type));
|
||||||
|
assert(ptype);
|
||||||
itype->flags |= ITF_POTION;
|
itype->flags |= ITF_POTION;
|
||||||
ptype->itype = itype;
|
ptype->itype = itype;
|
||||||
ptype->level = level;
|
ptype->level = level;
|
||||||
|
|
30
src/battle.c
30
src/battle.c
|
@ -488,7 +488,7 @@ contest_classic(int skilldiff, const armor_type * ar, const armor_type * sh)
|
||||||
mod *= (1 + ar->penalty);
|
mod *= (1 + ar->penalty);
|
||||||
if (sh != NULL)
|
if (sh != NULL)
|
||||||
mod *= (1 + sh->penalty);
|
mod *= (1 + sh->penalty);
|
||||||
vw = (int)(100 - ((100 - vw) * mod));
|
vw = (int)(100.0 - ((100.0 - (double)vw) * mod));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
p = (int)(rng_int() % 100);
|
p = (int)(rng_int() % 100);
|
||||||
|
@ -1226,7 +1226,7 @@ static void calculate_attack_type(troop dt, troop at, int type, bool missile,
|
||||||
static int crit_damage(int attskill, int defskill, const char *damage_formula) {
|
static int crit_damage(int attskill, int defskill, const char *damage_formula) {
|
||||||
int damage = 0;
|
int damage = 0;
|
||||||
if (rule_damage & DAMAGE_CRITICAL) {
|
if (rule_damage & DAMAGE_CRITICAL) {
|
||||||
double kritchance = (attskill * 3 - defskill) / 200.0;
|
double kritchance = ((double)attskill * 3.0 - (double)defskill) / 200.0;
|
||||||
int maxk = 4;
|
int maxk = 4;
|
||||||
|
|
||||||
kritchance = fmax(kritchance, 0.005);
|
kritchance = fmax(kritchance, 0.005);
|
||||||
|
@ -2079,6 +2079,7 @@ void dazzle(battle * b, troop * td)
|
||||||
|
|
||||||
void damage_building(battle * b, building * bldg, int damage_abs)
|
void damage_building(battle * b, building * bldg, int damage_abs)
|
||||||
{
|
{
|
||||||
|
assert(bldg);
|
||||||
bldg->size = MAX(1, bldg->size - damage_abs);
|
bldg->size = MAX(1, bldg->size - damage_abs);
|
||||||
|
|
||||||
/* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb<65>ude passen. */
|
/* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb<65>ude passen. */
|
||||||
|
@ -3428,11 +3429,12 @@ int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
||||||
|
|
||||||
battle *make_battle(region * r)
|
battle *make_battle(region * r)
|
||||||
{
|
{
|
||||||
battle *b = (battle *)calloc(1, sizeof(battle));
|
|
||||||
unit *u;
|
unit *u;
|
||||||
bfaction *bf;
|
bfaction *bf;
|
||||||
building * bld;
|
building * bld;
|
||||||
|
battle *b = (battle *)calloc(1, sizeof(battle));
|
||||||
|
|
||||||
|
assert(b);
|
||||||
/* Alle Mann raus aus der Burg! */
|
/* Alle Mann raus aus der Burg! */
|
||||||
for (bld = r->buildings; bld != NULL; bld = bld->next)
|
for (bld = r->buildings; bld != NULL; bld = bld->next)
|
||||||
bld->sizeleft = bld->size;
|
bld->sizeleft = bld->size;
|
||||||
|
@ -3450,6 +3452,7 @@ battle *make_battle(region * r)
|
||||||
}
|
}
|
||||||
if (!bf) {
|
if (!bf) {
|
||||||
bf = (bfaction *)calloc(1, sizeof(bfaction));
|
bf = (bfaction *)calloc(1, sizeof(bfaction));
|
||||||
|
assert(bf);
|
||||||
++b->nfactions;
|
++b->nfactions;
|
||||||
bf->faction = u->faction;
|
bf->faction = u->faction;
|
||||||
bf->next = b->factions;
|
bf->next = b->factions;
|
||||||
|
@ -3473,14 +3476,16 @@ static void free_side(side * si)
|
||||||
|
|
||||||
static void free_fighter(fighter * fig)
|
static void free_fighter(fighter * fig)
|
||||||
{
|
{
|
||||||
|
armor **ap = &fig->armors;
|
||||||
|
while (*ap) {
|
||||||
|
armor *a = *ap;
|
||||||
|
ap = &a->next;
|
||||||
|
free(a);
|
||||||
|
}
|
||||||
|
fig->armors = NULL;
|
||||||
while (fig->loot) {
|
while (fig->loot) {
|
||||||
i_free(i_remove(&fig->loot, fig->loot));
|
i_free(i_remove(&fig->loot, fig->loot));
|
||||||
}
|
}
|
||||||
while (fig->armors) {
|
|
||||||
armor *a = fig->armors;
|
|
||||||
fig->armors = a->next;
|
|
||||||
free(a);
|
|
||||||
}
|
|
||||||
free(fig->person);
|
free(fig->person);
|
||||||
free(fig->weapons);
|
free(fig->weapons);
|
||||||
|
|
||||||
|
@ -3492,13 +3497,14 @@ static void battle_free(battle * b) {
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
fighter *fnext = s->fighters;
|
fighter **fp = &s->fighters;
|
||||||
while (fnext) {
|
while (*fp) {
|
||||||
fighter *fig = fnext;
|
fighter *fig = *fp;
|
||||||
fnext = fig->next;
|
fp = &fig->next;
|
||||||
free_fighter(fig);
|
free_fighter(fig);
|
||||||
free(fig);
|
free(fig);
|
||||||
}
|
}
|
||||||
|
s->fighters = NULL;
|
||||||
free_side(s);
|
free_side(s);
|
||||||
}
|
}
|
||||||
free(b);
|
free(b);
|
||||||
|
|
|
@ -208,6 +208,7 @@ static buddy *get_friends(const unit * u, int *numfriends)
|
||||||
nf = *fr;
|
nf = *fr;
|
||||||
if (nf == NULL || nf->faction != u2->faction) {
|
if (nf == NULL || nf->faction != u2->faction) {
|
||||||
nf = malloc(sizeof(buddy));
|
nf = malloc(sizeof(buddy));
|
||||||
|
assert(nf);
|
||||||
nf->next = *fr;
|
nf->next = *fr;
|
||||||
nf->faction = u2->faction;
|
nf->faction = u2->faction;
|
||||||
nf->unit = u2;
|
nf->unit = u2;
|
||||||
|
@ -1004,11 +1005,15 @@ skill *add_skill(unit * u, skill_t sk)
|
||||||
skill *sv;
|
skill *sv;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
assert(u);
|
||||||
for (i = 0; i != u->skill_size; ++i) {
|
for (i = 0; i != u->skill_size; ++i) {
|
||||||
sv = u->skills + i;
|
sv = u->skills + i;
|
||||||
if (sv->id >= sk) break;
|
if (sv->id >= sk) break;
|
||||||
}
|
}
|
||||||
u->skills = realloc(u->skills, (1 + u->skill_size) * sizeof(skill));
|
sv = realloc(u->skills, (1 + u->skill_size) * sizeof(skill));
|
||||||
|
assert(sv);
|
||||||
|
u->skills = sv;
|
||||||
|
|
||||||
sv = u->skills + i;
|
sv = u->skills + i;
|
||||||
if (i < u->skill_size) {
|
if (i < u->skill_size) {
|
||||||
assert(sv->id != sk);
|
assert(sv->id != sk);
|
||||||
|
@ -1244,24 +1249,31 @@ int invisible(const unit * target, const unit * viewer)
|
||||||
*/
|
*/
|
||||||
void free_unit(unit * u)
|
void free_unit(unit * u)
|
||||||
{
|
{
|
||||||
|
struct reservation **pres = &u->reservations;
|
||||||
|
|
||||||
assert(!u->region);
|
assert(!u->region);
|
||||||
free(u->_name);
|
free(u->_name);
|
||||||
free_order(u->thisorder);
|
free_order(u->thisorder);
|
||||||
free_orders(&u->orders);
|
free_orders(&u->orders);
|
||||||
if (u->skills)
|
|
||||||
|
while (*pres) {
|
||||||
|
struct reservation *res = *pres;
|
||||||
|
pres = &res->next;
|
||||||
|
free(res);
|
||||||
|
}
|
||||||
|
u->reservations = NULL;
|
||||||
|
if (u->skills) {
|
||||||
free(u->skills);
|
free(u->skills);
|
||||||
|
u->skills = NULL;
|
||||||
|
}
|
||||||
while (u->items) {
|
while (u->items) {
|
||||||
item *it = u->items->next;
|
item *it = u->items->next;
|
||||||
u->items->next = NULL;
|
u->items->next = NULL;
|
||||||
i_free(u->items);
|
i_free(u->items);
|
||||||
u->items = it;
|
u->items = it;
|
||||||
}
|
}
|
||||||
while (u->attribs)
|
while (u->attribs) {
|
||||||
a_remove(&u->attribs, u->attribs);
|
a_remove(&u->attribs, u->attribs);
|
||||||
while (u->reservations) {
|
|
||||||
struct reservation *res = u->reservations;
|
|
||||||
u->reservations = res->next;
|
|
||||||
free(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ void register_special_direction(struct locale *lang, const char *name)
|
||||||
|
|
||||||
if (lang == locales) {
|
if (lang == locales) {
|
||||||
dir_lookup *dl = malloc(sizeof(dir_lookup));
|
dir_lookup *dl = malloc(sizeof(dir_lookup));
|
||||||
|
assert(dl);
|
||||||
dl->name = str;
|
dl->name = str;
|
||||||
dl->oldname = token;
|
dl->oldname = token;
|
||||||
dl->next = dir_name_lookup;
|
dl->next = dir_name_lookup;
|
||||||
|
|
Loading…
Reference in a new issue