minor optimizations, error checking (static analysis)

This commit is contained in:
Enno Rehling 2015-07-12 14:10:12 +02:00
parent 3fc3660152
commit 0a57933e30
3 changed files with 33 additions and 24 deletions

View File

@ -2339,8 +2339,9 @@ void do_regenerate(fighter * af)
ta.index = af->fighting;
while (ta.index--) {
af->person[ta.index].hp += effskill(au, SK_STAMINA);
af->person[ta.index].hp = _min(unit_max_hp(au), af->person[ta.index].hp);
struct person *p = af->person + ta.index;
p->hp += effskill(au, SK_STAMINA);
p->hp = _min(unit_max_hp(au), p->hp);
}
}

View File

@ -179,18 +179,6 @@ extern "C" {
/* ------------------------------------------------------------- */
/* Allgemeine Zauberwirkungen */
typedef struct curse {
struct curse *nexthash;
int no; /* 'Einheitennummer' dieses Curse */
const struct curse_type *type; /* Zeiger auf ein curse_type-struct */
int flags; /* WARNING: these are XORed with type->flags! */
int duration; /* Dauer der Verzauberung. Wird jede Runde vermindert */
double vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */
struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */
double effect;
variant data; /* pointer auf spezielle curse-unterstructs */
} curse;
#define c_flags(c) ((c)->type->flags ^ (c)->flags)
/* ------------------------------------------------------------- */
@ -200,17 +188,29 @@ extern "C" {
int typ;
int flags;
int mergeflags;
struct message *(*curseinfo) (const void *, objtype_t, const struct curse *,
int);
void(*change_vigour) (curse *, double);
int(*read) (struct storage * store, curse * c, void *target);
int(*write) (struct storage * store, const struct curse * c,
struct message *(*curseinfo) (const void *, objtype_t,
const struct curse *, int);
void(*change_vigour) (struct curse *, double);
int(*read) (struct storage * store, struct curse *, void *target);
int(*write) (struct storage * store, const struct curse *,
const void *target);
int(*cansee) (const struct faction *, const void *, objtype_t,
const struct curse *, int);
int(*age) (curse *);
int(*age) (struct curse *);
} curse_type;
typedef struct curse {
variant data; /* pointer auf spezielle curse-unterstructs */
struct curse *nexthash;
const curse_type *type; /* Zeiger auf ein curse_type-struct */
struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */
double vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */
double effect;
int no; /* 'Einheitennummer' dieses Curse */
int flags; /* WARNING: these are XORed with type->flags! */
int duration; /* Dauer der Verzauberung. Wird jede Runde vermindert */
} curse;
extern struct attrib_type at_curse;
void curse_write(const struct attrib *a, const void *owner,
struct storage *store);

View File

@ -2560,7 +2560,7 @@ static castorder *cast_cmd(unit * u, order * ord)
}
s = gettoken(token, sizeof(token));
}
if (!s || !s[0] || strlen(s) == 0) {
if (!s || !s[0]) {
/* Fehler "Es wurde kein Zauber angegeben" */
cmistake(u, ord, 172, MSG_MAGIC);
return 0;
@ -2571,7 +2571,7 @@ static castorder *cast_cmd(unit * u, order * ord)
/* Vertraute können auch Zauber sprechen, die sie selbst nicht
* können. unit_getspell findet aber nur jene Sprüche, die
* die Einheit beherrscht. */
if (!sp && is_familiar(u)) {
if (!sp && is_familiar(u)) {
caster = get_familiar_mage(u);
if (caster) {
familiar = u;
@ -2695,8 +2695,16 @@ static castorder *cast_cmd(unit * u, order * ord)
if (!s || *s == 0)
break;
if (p + 1 >= size) {
size *= 2;
params = (char**)realloc(params, sizeof(char *) * size);
char ** tmp;
tmp = (char**)realloc(params, sizeof(char *) * size * 2);
if (tmp) {
size *= 2;
params = tmp;
}
else {
log_error("error allocationg %d bytes: %s", size * 2, strerror(errno));
break;
}
}
params[p++] = _strdup(s);
}