cppcheck warnings

This commit is contained in:
Enno Rehling 2018-02-25 20:06:47 +01:00
parent b7dcee7e08
commit 079a55fe41
3 changed files with 13 additions and 16 deletions

View File

@ -476,14 +476,14 @@ static int count_materials(unit *u, const construction *type, int n, int complet
assert(canuse >= 0);
if (type->reqsize > 1) {
int need, prebuilt;
prebuilt =
required(completed, type->reqsize, type->materials[c].number);
for (; n;) {
need =
int prebuilt = required(completed, type->reqsize,
type->materials[c].number);
while (n > 0) {
int need =
required(completed + n, type->reqsize, type->materials[c].number);
if (need - prebuilt <= canuse)
if (need - prebuilt <= canuse) {
break;
}
--n; /* TODO: optimieren? */
}
}
@ -704,7 +704,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
* gefunden wurde, dann wird nicht einfach eine neue erbaut. Ansonsten
* baut man an der eigenen burg weiter. */
/* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */
/* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */
if (id > 0) { /* eine Nummer angegeben, keine neue Burg bauen */
b = findbuilding(id);
if (!b || b->region != u->region) { /* eine Burg mit dieser Nummer gibt es hier nicht */
@ -893,12 +893,12 @@ static void build_ship(unit * u, ship * sh, int want)
if (n)
ADDMSG(&u->faction->msgs,
msg_message("buildship", "ship unit size", sh, u, n));
msg_message("buildship", "ship unit size", sh, u, n));
}
void
create_ship(unit * u, const struct ship_type *newtype, int want,
order * ord)
order * ord)
{
ship *sh;
int msize;
@ -940,7 +940,7 @@ order * ord)
}
new_order =
create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale,
parameters[P_SHIP]), sh->no);
parameters[P_SHIP]), sh->no);
replace_order(&u->orders, ord, new_order);
free_order(new_order);

View File

@ -247,7 +247,7 @@ static void test_buildingowner_resets_when_empty(CuTest * tc)
u_set_building(u, bld);
CuAssertPtrEquals(tc, u, building_owner(bld));
u->number = 0;
CuAssertPtrEquals(tc, 0, building_owner(bld));
CuAssertPtrEquals(tc, NULL, building_owner(bld));
u->number = 1;
CuAssertPtrEquals(tc, u, building_owner(bld));
test_teardown();

View File

@ -121,10 +121,8 @@ static unit *unitorders(input *in, faction *f)
static faction *factionorders(void)
{
faction *f = NULL;
int fid = getid();
f = findfaction(fid);
faction *f = findfaction(fid);
if (f != NULL && !fval(f, FFL_NPC)) {
char token[128];
@ -231,9 +229,8 @@ int readorders(const char *filename)
{
input in;
int result;
FILE *F = fopen(filename, "r");
FILE *F = NULL;
F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;