forked from github/server
Merge pull request #368 from ennorehling/coverity-scan
coverity scan fixes
This commit is contained in:
commit
05239659c8
7 changed files with 47 additions and 31 deletions
|
@ -39,8 +39,8 @@ extern "C" {
|
||||||
#define BEHIND_ROW 2
|
#define BEHIND_ROW 2
|
||||||
#define AVOID_ROW 3
|
#define AVOID_ROW 3
|
||||||
#define FLEE_ROW 4
|
#define FLEE_ROW 4
|
||||||
#define LAST_ROW (NUMROWS-1)
|
|
||||||
#define FIRST_ROW FIGHT_ROW
|
#define FIRST_ROW FIGHT_ROW
|
||||||
|
#define LAST_ROW FLEE_ROW
|
||||||
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
||||||
|
|
||||||
struct message;
|
struct message;
|
||||||
|
|
|
@ -176,6 +176,7 @@ static void chaos(region * r)
|
||||||
set_money(u, u->number * (rng_int() % mfac));
|
set_money(u, u->number * (rng_int() % mfac));
|
||||||
fset(u, UFL_ISNEW | UFL_MOVED);
|
fset(u, UFL_ISNEW | UFL_MOVED);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case 2: /* Terrainveränderung */
|
case 2: /* Terrainveränderung */
|
||||||
if (!fval(r->terrain, FORBIDDEN_REGION)) {
|
if (!fval(r->terrain, FORBIDDEN_REGION)) {
|
||||||
if (!fval(r->terrain, SEA_REGION)) {
|
if (!fval(r->terrain, SEA_REGION)) {
|
||||||
|
|
|
@ -76,6 +76,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c
|
||||||
"\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, "
|
"\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, "
|
||||||
"\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F);
|
"\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F);
|
||||||
}
|
}
|
||||||
|
fclose(F);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -606,7 +606,6 @@ int read_borders(struct storage *store)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int bid = 0;
|
int bid = 0;
|
||||||
char zText[32];
|
char zText[32];
|
||||||
connection *b;
|
|
||||||
region *from, *to;
|
region *from, *to;
|
||||||
border_type *type;
|
border_type *type;
|
||||||
|
|
||||||
|
@ -629,6 +628,10 @@ int read_borders(struct storage *store)
|
||||||
READ_INT(store, &tid);
|
READ_INT(store, &tid);
|
||||||
from = findregionbyid(fid);
|
from = findregionbyid(fid);
|
||||||
to = findregionbyid(tid);
|
to = findregionbyid(tid);
|
||||||
|
if (!to || !from) {
|
||||||
|
log_warning("%s connection between incomplete regions %d and %d", zText, fid, tid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type = find_bordertype(zText);
|
type = find_bordertype(zText);
|
||||||
|
@ -644,26 +647,29 @@ int read_borders(struct storage *store)
|
||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
to = r;
|
to = r;
|
||||||
}
|
}
|
||||||
b = new_border(type, from, to);
|
if ((type->read && !type->write)) {
|
||||||
nextborder--; /* new_border erhöht den Wert */
|
log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0));
|
||||||
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) || !to || !from) {
|
else {
|
||||||
log_warning("erase invalid border '%s' between '%s' and '%s'\n", type->__name, regionname(from, 0), regionname(to, 0));
|
connection *b = new_border(type, from, to);
|
||||||
erase_border(b);
|
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;
|
return 0;
|
||||||
|
|
|
@ -449,7 +449,7 @@ static int nb_armor(const unit * u, int index)
|
||||||
static int
|
static int
|
||||||
damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
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 h;
|
||||||
int i, dead = 0, hp_rem = 0, heiltrank;
|
int i, dead = 0, hp_rem = 0, heiltrank;
|
||||||
double magres = magic_resistance(u);
|
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);
|
assert(u->number <= u->hp);
|
||||||
h = u->hp / u->number;
|
h = u->hp / u->number;
|
||||||
/* HP verteilen */
|
/* HP verteilen */
|
||||||
|
if (u->number < 20) {
|
||||||
|
hp = hpstack;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hp = malloc(u->number * sizeof(int));
|
||||||
|
}
|
||||||
for (i = 0; i < u->number; i++)
|
for (i = 0; i < u->number; i++)
|
||||||
hp[i] = h;
|
hp[i] = h;
|
||||||
h = u->hp - (u->number * 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);
|
scale_number(u, u->number - dead);
|
||||||
u->hp = hp_rem;
|
u->hp = hp_rem;
|
||||||
|
|
||||||
free(hp);
|
if (hp != hpstack) {
|
||||||
|
free(hp);
|
||||||
|
}
|
||||||
|
|
||||||
return dead;
|
return dead;
|
||||||
}
|
}
|
||||||
|
@ -525,7 +533,7 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
||||||
void drown(region * r)
|
void drown(region * r)
|
||||||
{
|
{
|
||||||
if (fval(r->terrain, SEA_REGION)) {
|
if (fval(r->terrain, SEA_REGION)) {
|
||||||
unit **up = up = &r->units;
|
unit **up = &r->units;
|
||||||
while (*up) {
|
while (*up) {
|
||||||
unit *u = *up;
|
unit *u = *up;
|
||||||
|
|
||||||
|
@ -580,7 +588,7 @@ volcano_destruction(region * volcano, region * r, const char *damage)
|
||||||
rsettrees(r, 0, 0);
|
rsettrees(r, 0, 0);
|
||||||
|
|
||||||
a = a_find(r->attribs, &at_reduceproduction);
|
a = a_find(r->attribs, &at_reduceproduction);
|
||||||
if (a) {
|
if (!a) {
|
||||||
a = a_add(&r->attribs, make_reduceproduction(percent, time));
|
a = a_add(&r->attribs, make_reduceproduction(percent, time));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -263,6 +263,7 @@ void convert_firewall_timeouts(connection * b, attrib * a)
|
||||||
wall_data *fd = (wall_data *)b->data.v;
|
wall_data *fd = (wall_data *)b->data.v;
|
||||||
fd->countdown = a->data.i;
|
fd->countdown = a->data.i;
|
||||||
}
|
}
|
||||||
|
a = a->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,22 +91,21 @@ void crt_register(const struct message_type *mtype)
|
||||||
crt = crt->next;
|
crt = crt->next;
|
||||||
}
|
}
|
||||||
if (!crt) {
|
if (!crt) {
|
||||||
int i;
|
|
||||||
crt = malloc(sizeof(crmessage_type));
|
crt = malloc(sizeof(crmessage_type));
|
||||||
crt->mtype = mtype;
|
crt->mtype = mtype;
|
||||||
crt->next = crtypes[hash];
|
crt->next = crtypes[hash];
|
||||||
crtypes[hash] = crt;
|
crtypes[hash] = crt;
|
||||||
if (mtype->nparameters > 0) {
|
if (mtype->nparameters > 0) {
|
||||||
|
int i;
|
||||||
crt->renderers = malloc(sizeof(tostring_f) * mtype->nparameters);
|
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 {
|
else {
|
||||||
crt->renderers = NULL;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue