Merge pull request #368 from ennorehling/coverity-scan

coverity scan fixes
This commit is contained in:
Enno Rehling 2015-11-05 11:53:22 +01:00
commit 05239659c8
7 changed files with 47 additions and 31 deletions

View File

@ -39,8 +39,8 @@ extern "C" {
#define BEHIND_ROW 2
#define AVOID_ROW 3
#define FLEE_ROW 4
#define LAST_ROW (NUMROWS-1)
#define FIRST_ROW FIGHT_ROW
#define LAST_ROW FLEE_ROW
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
struct message;

View File

@ -176,6 +176,7 @@ static void chaos(region * r)
set_money(u, u->number * (rng_int() % mfac));
fset(u, UFL_ISNEW | UFL_MOVED);
}
break;
case 2: /* Terrainveränderung */
if (!fval(r->terrain, FORBIDDEN_REGION)) {
if (!fval(r->terrain, SEA_REGION)) {

View File

@ -76,6 +76,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c
"\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, "
"\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F);
}
fclose(F);
return 0;
}
return -1;

View File

@ -606,7 +606,6 @@ int read_borders(struct storage *store)
for (;;) {
int bid = 0;
char zText[32];
connection *b;
region *from, *to;
border_type *type;
@ -629,6 +628,10 @@ int read_borders(struct storage *store)
READ_INT(store, &tid);
from = findregionbyid(fid);
to = findregionbyid(tid);
if (!to || !from) {
log_warning("%s connection between incomplete regions %d and %d", zText, fid, tid);
continue;
}
}
type = find_bordertype(zText);
@ -644,26 +647,29 @@ int read_borders(struct storage *store)
if (r != NULL)
to = r;
}
b = new_border(type, from, to);
nextborder--; /* new_border erhöht den Wert */
b->id = bid;
assert(bid <= nextborder);
if (type->read)
type->read(b, store);
if (global.data_version < NOBORDERATTRIBS_VERSION) {
attrib *a = NULL;
int result = a_read(store, &a, b);
if (border_convert_cb)
border_convert_cb(b, a);
while (a) {
a_remove(&a, a);
}
if (result < 0)
return result;
if ((type->read && !type->write)) {
log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0));
}
if ((type->read && !type->write) || !to || !from) {
log_warning("erase invalid border '%s' between '%s' and '%s'\n", type->__name, regionname(from, 0), regionname(to, 0));
erase_border(b);
else {
connection *b = new_border(type, from, to);
nextborder--; /* new_border erhöht den Wert */
b->id = bid;
assert(bid <= nextborder);
if (type->read)
type->read(b, store);
if (global.data_version < NOBORDERATTRIBS_VERSION) {
attrib *a = NULL;
int result = a_read(store, &a, b);
if (border_convert_cb) {
border_convert_cb(b, a);
}
while (a) {
a_remove(&a, a);
}
if (result < 0) {
return result;
}
}
}
}
return 0;

View File

@ -449,7 +449,7 @@ static int nb_armor(const unit * u, int index)
static int
damage_unit(unit * u, const char *dam, bool physical, bool magic)
{
int *hp = malloc(u->number * sizeof(int));
int *hp, hpstack[20];
int h;
int i, dead = 0, hp_rem = 0, heiltrank;
double magres = magic_resistance(u);
@ -462,6 +462,12 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
assert(u->number <= u->hp);
h = u->hp / u->number;
/* HP verteilen */
if (u->number < 20) {
hp = hpstack;
}
else {
hp = malloc(u->number * sizeof(int));
}
for (i = 0; i < u->number; i++)
hp[i] = h;
h = u->hp - (u->number * h);
@ -517,7 +523,9 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
scale_number(u, u->number - dead);
u->hp = hp_rem;
free(hp);
if (hp != hpstack) {
free(hp);
}
return dead;
}
@ -525,7 +533,7 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
void drown(region * r)
{
if (fval(r->terrain, SEA_REGION)) {
unit **up = up = &r->units;
unit **up = &r->units;
while (*up) {
unit *u = *up;
@ -580,7 +588,7 @@ volcano_destruction(region * volcano, region * r, const char *damage)
rsettrees(r, 0, 0);
a = a_find(r->attribs, &at_reduceproduction);
if (a) {
if (!a) {
a = a_add(&r->attribs, make_reduceproduction(percent, time));
}
else {

View File

@ -263,6 +263,7 @@ void convert_firewall_timeouts(connection * b, attrib * a)
wall_data *fd = (wall_data *)b->data.v;
fd->countdown = a->data.i;
}
a = a->next;
}
}

View File

@ -91,22 +91,21 @@ void crt_register(const struct message_type *mtype)
crt = crt->next;
}
if (!crt) {
int i;
crt = malloc(sizeof(crmessage_type));
crt->mtype = mtype;
crt->next = crtypes[hash];
crtypes[hash] = crt;
if (mtype->nparameters > 0) {
int i;
crt->renderers = malloc(sizeof(tostring_f) * mtype->nparameters);
/* can be scrapped for memory vs. speed */
for (i = 0; i != mtype->nparameters; ++i) {
crt->renderers[i] = tsf_find(mtype->types[i]->name);
}
}
else {
crt->renderers = NULL;
}
/* can be scrapped for memory vs. speed */
for (i = 0; i != mtype->nparameters; ++i) {
crt->renderers[i] = tsf_find(mtype->types[i]->name);
}
}
}