cppcheck: scope reductions and a false positive.

This commit is contained in:
Enno Rehling 2018-02-11 16:14:00 +01:00
parent 398a258658
commit b5ea102372
4 changed files with 16 additions and 17 deletions

View file

@ -1190,15 +1190,13 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
assert(avail == 0 || nreq == 0); assert(avail == 0 || nreq == 0);
} }
typedef void(*allocate_function) (const resource_type *, struct region *, static void allocate(const resource_type *rtype, region *r, allocation *data) {
struct allocation *);
static allocate_function get_allocator(const struct resource_type *rtype)
{
if (rtype->raw) { if (rtype->raw) {
return leveled_allocation; leveled_allocation(rtype, r, data);
}
else {
attrib_allocation(rtype, r, data);
} }
return attrib_allocation;
} }
void split_allocations(region * r) void split_allocations(region * r)
@ -1207,11 +1205,10 @@ void split_allocations(region * r)
while (*p_alist) { while (*p_alist) {
allocation_list *alist = *p_alist; allocation_list *alist = *p_alist;
const resource_type *rtype = alist->type; const resource_type *rtype = alist->type;
allocate_function alloc = get_allocator(rtype);
const item_type *itype = resource2item(rtype); const item_type *itype = resource2item(rtype);
allocation **p_al = &alist->data; allocation **p_al = &alist->data;
alloc(rtype, r, alist->data); allocate(rtype, r, alist->data);
while (*p_al) { while (*p_al) {
allocation *al = *p_al; allocation *al = *p_al;

View file

@ -304,7 +304,6 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
}; };
starget *targetp; starget *targetp;
char cp = *params++; char cp = *params++;
int i, maxparam = 0;
const char *locp; const char *locp;
const char *syntaxp = sp->syntax; const char *syntaxp = sp->syntax;
@ -359,6 +358,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
else if (cp == 'k') { else if (cp == 'k') {
int i, maxparam = 0;
bool multi = false; bool multi = false;
if (params && *params == 'c') { if (params && *params == 'c') {
/* skip over a potential id */ /* skip over a potential id */

View file

@ -575,7 +575,6 @@ report_resources(const region * r, resource_report * result, int size,
if (see_unit) { if (see_unit) {
rawmaterial *res = r->resources; rawmaterial *res = r->resources;
while (res) { while (res) {
int maxskill = 0;
const item_type *itype = resource2item(res->rtype); const item_type *itype = resource2item(res->rtype);
int minskill = itype->construction->minskill; int minskill = itype->construction->minskill;
skill_t skill = itype->construction->skill; skill_t skill = itype->construction->skill;
@ -588,6 +587,7 @@ report_resources(const region * r, resource_report * result, int size,
} }
else { else {
const unit *u; const unit *u;
int maxskill = 0;
for (u = r->units; visible != res->amount && u != NULL; u = u->next) { for (u = r->units; visible != res->amount && u != NULL; u = u->next) {
if (u->faction == viewer) { if (u->faction == viewer) {
int s = effskill(u, skill, 0); int s = effskill(u, skill, 0);
@ -923,7 +923,7 @@ spskill(char *buffer, size_t size, const struct locale * lang,
const struct unit * u, struct skill * sv, int *dh, int days) const struct unit * u, struct skill * sv, int *dh, int days)
{ {
char *bufp = buffer; char *bufp = buffer;
int i, effsk; int effsk;
if (!u->number) if (!u->number)
return 0; return 0;
@ -953,7 +953,7 @@ spskill(char *buffer, size_t size, const struct locale * lang,
} }
if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) { if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) {
i = u_geteffstealth(u); int i = u_geteffstealth(u);
if (i >= 0) { if (i >= 0) {
if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0) if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -2276,7 +2276,6 @@ static void eval_trail(struct opstack **stack, const void *userdata)
{ /* order -> string */ { /* order -> string */
const faction *report = (const faction *)userdata; const faction *report = (const faction *)userdata;
const struct locale *lang = report ? report->locale : default_locale; const struct locale *lang = report ? report->locale : default_locale;
int i, end = 0, begin = 0;
const arg_regions *aregs = (const arg_regions *)opop(stack).v; const arg_regions *aregs = (const arg_regions *)opop(stack).v;
char buf[512]; char buf[512];
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
@ -2288,6 +2287,7 @@ static void eval_trail(struct opstack **stack, const void *userdata)
#endif #endif
if (aregs != NULL) { if (aregs != NULL) {
int i, end = 0, begin = 0;
end = aregs->nregions; end = aregs->nregions;
for (i = begin; i < end; ++i) { for (i = begin; i < end; ++i) {
region *r = aregs->regions[i]; region *r = aregs->regions[i];

View file

@ -475,10 +475,10 @@ typedef enum study_rule_t {
static double study_speedup(unit * u, skill_t s, study_rule_t rule) static double study_speedup(unit * u, skill_t s, study_rule_t rule)
{ {
#define MINTURN 16 #define MINTURN 16
double learnweeks = 0;
int i;
if (turn > MINTURN) { if (turn > MINTURN) {
if (rule == STUDY_FASTER) { if (rule == STUDY_FASTER) {
double learnweeks = 0;
int i;
for (i = 0; i != u->skill_size; ++i) { for (i = 0; i != u->skill_size; ++i) {
skill *sv = u->skills + i; skill *sv = u->skills + i;
if (sv->id == s) { if (sv->id == s) {
@ -491,6 +491,8 @@ static double study_speedup(unit * u, skill_t s, study_rule_t rule)
return 2.0; /* If the skill was not found it is the first study. */ return 2.0; /* If the skill was not found it is the first study. */
} }
if (rule == STUDY_AUTOTEACH) { if (rule == STUDY_AUTOTEACH) {
double learnweeks = 0;
int i;
for (i = 0; i != u->skill_size; ++i) { for (i = 0; i != u->skill_size; ++i) {
skill *sv = u->skills + i; skill *sv = u->skills + i;
learnweeks += (sv->level * (sv->level + 1) / 2.0); learnweeks += (sv->level * (sv->level + 1) / 2.0);
@ -547,7 +549,6 @@ int study_cmd(unit * u, order * ord)
{ {
region *r = u->region; region *r = u->region;
int p; int p;
magic_t mtyp;
int l; int l;
int studycost, days; int studycost, days;
double multi = 1.0; double multi = 1.0;
@ -621,6 +622,7 @@ int study_cmd(unit * u, order * ord)
} }
if (sk == SK_MAGIC) { if (sk == SK_MAGIC) {
magic_t mtyp;
if (u->number > 1) { if (u->number > 1) {
cmistake(u, ord, 106, MSG_MAGIC); cmistake(u, ord, 106, MSG_MAGIC);
return -1; return -1;