Skip to content

Commit

Permalink
fix some static analysis flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Jun 16, 2024
1 parent dabc541 commit b65b451
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/gmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ static void show_help(void)
"s: seed next player from newfactions at current region",
"A: reset area (set region age to 0) for whole contiguos region",
"c: clear (reset resources) region under cursor",
"C: clear rectangle under cursor (2 regions up and to the right)"
"C: clear rectangle under cursor (2 regions up and to the right)",
"",
"h: mark regions ... n: none, i: island under cursor, t: terrain type, s: with ships,",
" u: with units, p: with player units, m: with monsters, f: with units of a faction,",
Expand Down
22 changes: 11 additions & 11 deletions src/kernel/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,28 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
const char *str = (const char *)LOC(lang, keyword(kwd));
assert(str);
sbs_strcat(&sbs, str);
if (ord->id < 0) {
skill_t sk = (skill_t)(100+ord->id);
if (ord->id >= 0) {
order_data *od = odata_load(ord->id);
str = OD_STRING(od);
if (str) {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, str);
}
odata_release(od);
} else if (100 + ord->id < MAXSKILLS) {
skill_t sk = (skill_t)(100 + ord->id);
str = skillname(sk, lang);
if (str) {
if (strchr(str, ' ') == NULL) {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, str);
}
}
else {
sbs_strcat(&sbs, " \"");
sbs_strcat(&sbs, str);
sbs_strcat(&sbs, "\"");
}
}
} else {
order_data *od = odata_load(ord->id);
str = OD_STRING(od);
if (str) {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, str);
}
odata_release(od);
}
}
return sbuffer;
Expand Down
1 change: 1 addition & 0 deletions src/kernel/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ static void create_land(region *r) {
setluxuries(r, nb[p].type);
}
}
arrfree(nb);
}

void terraform_region(region * r, const terrain_type * terrain)
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ static void fix_resource_values(region* r)

static void read_landregion(gamedata* data, region* r)
{
char info[DISPLAYSIZE];
char name[NAMESIZE];
int n, i;
r->land = calloc(1, sizeof(land_region));
Expand All @@ -752,9 +751,10 @@ static void read_landregion(gamedata* data, region* r)
r->land->name = str_strdup(name);

if (data->version >= LANDDISPLAY_VERSION) {
char info[DISPLAYSIZE];
read_regioninfo(data, r, info, sizeof(info));
region_setinfo(r, info);
}
region_setinfo(r, info);
READ_INT(data->store, &i);
if (i < 0) {
log_error("number of trees in %s is %d.", regionname(r, NULL), i);
Expand Down
19 changes: 13 additions & 6 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,13 +1395,20 @@ static bool roadto(const region * r, direction_t dir)
}
}

if (r->terrain->max_road <= 0)
if (r->terrain->max_road <= 0) {
return false;
if (r2->terrain->max_road <= 0)
}
if (r2->terrain->max_road <= 0) {
return false;
if (rroad(r, dir) < r->terrain->max_road)
}
if (rroad(r, dir) < r->terrain->max_road) {
return false;
if (rroad(r2, dir_invert(dir)) < r2->terrain->max_road)
}
dir = dir_invert(dir);
if (dir >= MAXDIRECTIONS || dir == NODIRECTION) {
return false;
}
if (rroad(r2, dir) < r2->terrain->max_road)
return false;
return true;
}
Expand Down Expand Up @@ -1874,8 +1881,8 @@ void harbour_taxes(region *r, unit *captain, unit *harbourmaster)
if (trans) {
message *msg =
msg_message("harbor_trade", "unit items ship", harbourmaster, trans,
u->ship);
add_message(&u->faction->msgs, msg);
sh);
add_message(&captain->faction->msgs, msg);
add_message(&harbourmaster->faction->msgs, msg);
msg_release(msg);
while (trans)
Expand Down
2 changes: 1 addition & 1 deletion src/reports.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static void spskill(struct skill* sv, const struct unit *u, const struct locale

if (sv->id == SK_MAGIC) {
magic_t mtype = unit_get_magic(u);
if (mtype != M_GRAY) {
if (mtype != M_GRAY && mtype != M_NONE) {
sbs_strcat(sbp, magic_name(mtype, lang));
sbs_strcat(sbp, " ");
}
Expand Down
2 changes: 1 addition & 1 deletion src/study.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ int teach_cmd(unit * teacher, struct order *ord)
/* Input ist nun von student->thisorder !! */
init_order(student->thisorder, student->faction->locale);
sk = getskill(student->faction->locale);
if (sk != NOSKILL
if (sk != NOSKILL && sk < MAXSKILLS
&& effskill_study(teacher, sk) - TEACHDIFFERENCE >= effskill(student, sk, NULL)) {
teaching -= teach_unit(teacher, student, teaching, sk, true, &academy_students);
}
Expand Down
4 changes: 3 additions & 1 deletion src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ building_type * test_create_buildingtype(const char * name)
if (btype->a_stages) {
con = &btype->a_stages[0].construction;
} else {
building_stage *stage = arraddnptr(btype->a_stages, 1);
building_stage *stage;
arrsetlen(btype->a_stages, 1);
stage = btype->a_stages;
if (stage) {
stage->name = NULL;
con = &stage->construction;
Expand Down
3 changes: 0 additions & 3 deletions src/util/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ utf8_decode(wchar_t * ucs4_character, const char * utf8_string,
return EILSEQ;
}
*length = (size_t)size;
if (codepoint > WCHAR_MAX) {
return ENOMEM;
}
*ucs4_character = (wchar_t)codepoint;
return 0;
}
Expand Down

0 comments on commit b65b451

Please sign in to comment.