forked from github/server
static analysis warnings.
PVS-Studio warnings reduced or suppressed.
This commit is contained in:
parent
ea6cd2ca32
commit
7f9313f1a7
12 changed files with 56 additions and 54 deletions
|
@ -295,7 +295,7 @@ static void a_initeffect(attrib * a)
|
|||
a->data.v = calloc(sizeof(effect_data), 1);
|
||||
}
|
||||
|
||||
static void a_finalizeeffect(attrib * a)
|
||||
static void a_finalizeeffect(attrib * a) //-V524
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
|
|
@ -3984,7 +3984,7 @@ static bool start_battle(region * r, battle ** bp)
|
|||
while (a && a->type == &at_curse) {
|
||||
curse *c = (curse *)a->data.v;
|
||||
if (c->type == calm_ct
|
||||
&& curse_geteffect(c) == u2->faction->subscription) {
|
||||
&& curse_geteffect_int(c) == u2->faction->subscription) {
|
||||
if (curse_active(c)) {
|
||||
calm = true;
|
||||
break;
|
||||
|
@ -4275,9 +4275,7 @@ void do_battle(region * r)
|
|||
/* Hier ist das Gefecht beendet, und wir k<>nnen die
|
||||
* Hilfsstrukturen * wieder l<EFBFBD>schen: */
|
||||
|
||||
if (b) {
|
||||
free_battle(b);
|
||||
}
|
||||
free_battle(b);
|
||||
}
|
||||
|
||||
void do_battles(void) {
|
||||
|
|
|
@ -72,7 +72,7 @@ extern "C" {
|
|||
unsigned char relations[MAXSIDES];
|
||||
struct side *enemies[MAXSIDES];
|
||||
struct fighter *fighters;
|
||||
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
||||
unsigned int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
||||
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
||||
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kaempfer, z.B. Schattenritter. */
|
||||
int alive; /* Die Partei hat den Kampf verlassen */
|
||||
|
|
17
src/json.c
17
src/json.c
|
@ -1,8 +1,9 @@
|
|||
#include "platform.h"
|
||||
#include <util/base36.h>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include <util/base36.h>
|
||||
#include <util/log.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -22,12 +23,20 @@ int json_import(struct stream * out) {
|
|||
assert(out && out->api);
|
||||
while (!out->api->readln(out->handle, buffer, sizeof(buffer))) {
|
||||
size_t len = strlen(buffer);
|
||||
data = (char *)realloc(data, sz + len + 1);
|
||||
char *tmp;
|
||||
tmp = (char *)realloc(data, sz + len + 1);
|
||||
if (!tmp) {
|
||||
log_fatal("allocation failure in json_import");
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
data = tmp;
|
||||
memcpy(data + sz, buffer, len);
|
||||
sz += len;
|
||||
data[sz] = 0;
|
||||
}
|
||||
json = cJSON_Parse(data);
|
||||
free(data);
|
||||
child = cJSON_GetObjectItem(json, "regions");
|
||||
if (child && child->type == cJSON_Object) {
|
||||
cJSON *j;
|
||||
|
@ -64,7 +73,7 @@ int json_export(stream * out, int flags) {
|
|||
cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject());
|
||||
for (p = planes; p; p = p->next) {
|
||||
cJSON *data;
|
||||
_snprintf(id, sizeof(id), "%u", p->id);
|
||||
_snprintf(id, sizeof(id), "%d", p->id);
|
||||
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
|
||||
cJSON_AddNumberToObject(data, "x", p->minx);
|
||||
cJSON_AddNumberToObject(data, "y", p->miny);
|
||||
|
@ -76,7 +85,7 @@ int json_export(stream * out, int flags) {
|
|||
cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject());
|
||||
for (r = regions; r; r = r->next) {
|
||||
cJSON *data;
|
||||
_snprintf(id, sizeof(id), "%u", r->uid);
|
||||
_snprintf(id, sizeof(id), "%d", r->uid);
|
||||
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
|
||||
cJSON_AddNumberToObject(data, "x", r->x);
|
||||
cJSON_AddNumberToObject(data, "y", r->y);
|
||||
|
|
|
@ -648,7 +648,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
|
|||
* verfügbaren Fläche ab. In Gletschern gibt es weniger
|
||||
* Möglichkeiten als in Ebenen. */
|
||||
sprout = 0;
|
||||
seedchance = (1000 * region_maxworkers(r2)) / (double)r2->terrain->size;
|
||||
seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size;
|
||||
for (i = 0; i < seeds / MAXDIRECTIONS; i++) {
|
||||
if (rng_int() % 10000 < seedchance)
|
||||
sprout++;
|
||||
|
@ -1269,7 +1269,6 @@ static void remove_idle_players(void)
|
|||
} else {
|
||||
if (fval(f, FFL_NOIDLEOUT)) {
|
||||
f->lastorders = turn;
|
||||
fp = &f->next;
|
||||
}
|
||||
else if (turn != f->lastorders) {
|
||||
char info[256];
|
||||
|
@ -2995,9 +2994,9 @@ static void ageing(void)
|
|||
for (up = &r->units; *up;) {
|
||||
unit *u = *up;
|
||||
a_age(&u->attribs, u);
|
||||
if (u == *up)
|
||||
if (u == *up)
|
||||
handle_event(u->attribs, "timer", u);
|
||||
if (u == *up)
|
||||
if (u == *up) //-V581
|
||||
up = &(*up)->next;
|
||||
}
|
||||
|
||||
|
@ -3007,7 +3006,7 @@ static void ageing(void)
|
|||
a_age(&s->attribs, s);
|
||||
if (s == *sp)
|
||||
handle_event(s->attribs, "timer", s);
|
||||
if (s == *sp)
|
||||
if (s == *sp) //-V581
|
||||
sp = &(*sp)->next;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ static void a_initicastle(struct attrib *a)
|
|||
a->data.v = calloc(sizeof(icastle_data), 1);
|
||||
}
|
||||
|
||||
static void a_finalizeicastle(struct attrib *a)
|
||||
static void a_finalizeicastle(struct attrib *a) //-V524
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
|
13
src/prefix.c
13
src/prefix.c
|
@ -1,6 +1,8 @@
|
|||
#include <platform.h>
|
||||
#include "prefix.h"
|
||||
|
||||
#include <util/log.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -10,7 +12,7 @@ char **race_prefixes = NULL;
|
|||
static size_t size = 4;
|
||||
static unsigned int next = 0;
|
||||
|
||||
void add_raceprefix(const char *prefix)
|
||||
int add_raceprefix(const char *prefix)
|
||||
{
|
||||
assert(prefix);
|
||||
if (race_prefixes == NULL) {
|
||||
|
@ -19,11 +21,18 @@ void add_raceprefix(const char *prefix)
|
|||
race_prefixes = malloc(size * sizeof(char *));
|
||||
}
|
||||
if (next + 1 == size) {
|
||||
char **tmp;
|
||||
tmp = realloc(race_prefixes, 2 * size * sizeof(char *));
|
||||
if (!tmp) {
|
||||
log_fatal("allocation failure");
|
||||
return 1;
|
||||
}
|
||||
race_prefixes = tmp;
|
||||
size *= 2;
|
||||
race_prefixes = realloc(race_prefixes, size * sizeof(char *));
|
||||
}
|
||||
race_prefixes[next++] = _strdup(prefix);
|
||||
race_prefixes[next] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_prefixes(void) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void add_raceprefix(const char *);
|
||||
int add_raceprefix(const char *);
|
||||
char **race_prefixes; // zero-terminated array of valid prefixes
|
||||
void free_prefixes(void);
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
static void test_add_prefix(CuTest *tc) {
|
||||
test_setup();
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes);
|
||||
add_raceprefix("sea");
|
||||
CuAssertIntEquals(tc, 0, add_raceprefix("sea"));
|
||||
CuAssertPtrNotNull(tc, race_prefixes);
|
||||
CuAssertStrEquals(tc, "sea", race_prefixes[0]);
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes[1]);
|
||||
add_raceprefix("moon");
|
||||
CuAssertIntEquals(tc, 0, add_raceprefix("moon"));
|
||||
CuAssertStrEquals(tc, "sea", race_prefixes[0]);
|
||||
CuAssertStrEquals(tc, "moon", race_prefixes[1]);
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes[2]);
|
||||
|
|
|
@ -69,7 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern struct attrib_type at_unitdissolve;
|
||||
|
||||
/* In a->data.ca[1] steht der Prozentsatz mit dem sich die Einheit
|
||||
* auflöst, in a->data.ca[0] kann angegeben werden, wohin die Personen
|
||||
* aufl<EFBFBD>st, in a->data.ca[0] kann angegeben werden, wohin die Personen
|
||||
* verschwinden. Passiert bereits in der ersten Runde! */
|
||||
static void dissolve_units(void)
|
||||
{
|
||||
|
@ -442,12 +442,12 @@ static void melt_iceberg(region * r)
|
|||
ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r));
|
||||
}
|
||||
|
||||
/* driftrichtung löschen */
|
||||
/* driftrichtung l<EFBFBD>schen */
|
||||
a = a_find(r->attribs, &at_iceberg);
|
||||
if (a)
|
||||
a_remove(&r->attribs, a);
|
||||
|
||||
/* Gebäude löschen */
|
||||
/* Geb<EFBFBD>ude l<>schen */
|
||||
while (r->buildings) {
|
||||
remove_building(&r->buildings, r->buildings);
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ static void melt_iceberg(region * r)
|
|||
/* in Ozean wandeln */
|
||||
terraform_region(r, newterrain(T_OCEAN));
|
||||
|
||||
/* Einheiten, die nicht schwimmen können oder in Schiffen sind,
|
||||
/* Einheiten, die nicht schwimmen k<EFBFBD>nnen oder in Schiffen sind,
|
||||
* ertrinken */
|
||||
drown(r);
|
||||
}
|
||||
|
@ -519,13 +519,13 @@ static void move_iceberg(region * r)
|
|||
freset(sh, SF_SELECT);
|
||||
|
||||
for (sh = r->ships; sh; sh = sh->next) {
|
||||
/* Meldung an Kapitän */
|
||||
/* Meldung an Kapit<EFBFBD>n */
|
||||
double dmg = config_get_flt("rules.ship.damage.intoiceberg", 0.1);
|
||||
damage_ship(sh, dmg);
|
||||
fset(sh, SF_SELECT);
|
||||
}
|
||||
|
||||
/* Personen, Schiffe und Gebäude verschieben */
|
||||
/* Personen, Schiffe und Geb<EFBFBD>ude verschieben */
|
||||
while (rc->buildings) {
|
||||
rc->buildings->region = r;
|
||||
translist(&rc->buildings, &r->buildings, rc->buildings);
|
||||
|
@ -544,7 +544,7 @@ static void move_iceberg(region * r)
|
|||
u_set_building(u, b); /* undo leave-prevention */
|
||||
}
|
||||
|
||||
/* Beschädigte Schiffe können sinken */
|
||||
/* Besch<EFBFBD>digte Schiffe k<>nnen sinken */
|
||||
|
||||
for (sh = r->ships; sh;) {
|
||||
shn = sh->next;
|
||||
|
@ -725,7 +725,7 @@ static void orc_growth(void)
|
|||
}
|
||||
}
|
||||
|
||||
/** Talente von Dämonen verschieben sich.
|
||||
/** Talente von D<EFBFBD>monen verschieben sich.
|
||||
*/
|
||||
static void demon_skillchanges(void)
|
||||
{
|
||||
|
@ -760,7 +760,7 @@ static void icebergs(void)
|
|||
}
|
||||
|
||||
#define HERBS_ROT /* herbs owned by units have a chance to rot. */
|
||||
#define HERBROTCHANCE 5 /* Verrottchance für Kräuter (ifdef HERBS_ROT) */
|
||||
#define HERBROTCHANCE 5 /* Verrottchance f<EFBFBD>r Kr<4B>uter (ifdef HERBS_ROT) */
|
||||
#ifdef HERBS_ROT
|
||||
static void rotting_herbs(void)
|
||||
{
|
||||
|
|
12
src/report.c
12
src/report.c
|
@ -915,14 +915,16 @@ static void describe(struct stream *out, const region * r, faction * f)
|
|||
bool transparent = b->type->transparent(b, f);
|
||||
const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE);
|
||||
|
||||
if (!transparent)
|
||||
if (!transparent) {
|
||||
see[d] = false;
|
||||
}
|
||||
if (!see_border(b, f, r)) {
|
||||
b = b->next;
|
||||
continue;
|
||||
}
|
||||
while (e && (e->transparent != transparent || strcmp(name, e->name)))
|
||||
while (e && (e->transparent != transparent || strcmp(name, e->name)!=0)) {
|
||||
e = e->next;
|
||||
}
|
||||
if (!e) {
|
||||
e = calloc(sizeof(struct edge), 1);
|
||||
e->name = _strdup(name);
|
||||
|
@ -2248,10 +2250,8 @@ report_plaintext(const char *filename, report_context * ctx,
|
|||
*bufp = 0;
|
||||
centre(out, buf, true);
|
||||
newline(out);
|
||||
if (description == NULL) {
|
||||
const char *potiontext = mkname("potion", pname);
|
||||
description = LOC(f->locale, potiontext);
|
||||
}
|
||||
description = mkname("potion", pname);
|
||||
description = LOC(f->locale, description);
|
||||
centre(out, description, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -720,7 +720,7 @@ size_t size)
|
|||
}
|
||||
}
|
||||
if (!isbattle) {
|
||||
bool printed = 0;
|
||||
int printed = 0;
|
||||
order *ord;;
|
||||
for (ord = u->old_orders; ord; ord = ord->next) {
|
||||
keyword_t kwd = getkeyword(ord);
|
||||
|
@ -1587,7 +1587,7 @@ static void var_free_resources(variant x)
|
|||
x.v = 0;
|
||||
}
|
||||
|
||||
static void var_free_regions(variant x)
|
||||
static void var_free_regions(variant x) //-V524
|
||||
{
|
||||
free(x.v);
|
||||
}
|
||||
|
@ -1716,18 +1716,6 @@ static void eval_curse(struct opstack **stack, const void *userdata)
|
|||
opush(stack, var);
|
||||
}
|
||||
|
||||
static void eval_unitname(struct opstack **stack, const void *userdata)
|
||||
{ /* unit -> string */
|
||||
const struct faction *f = (const struct faction *)userdata;
|
||||
const struct unit *u = (const struct unit *)opop(stack).v;
|
||||
const char *c = u ? unit_getname(u) : LOC(f->locale, "an_unknown_unit");
|
||||
size_t len = strlen(c);
|
||||
variant var;
|
||||
|
||||
var.v = strcpy(balloc(len + 1), c);
|
||||
opush(stack, var);
|
||||
}
|
||||
|
||||
static void eval_unitid(struct opstack **stack, const void *userdata)
|
||||
{ /* unit -> int */
|
||||
const struct faction *f = (const struct faction *)userdata;
|
||||
|
@ -1836,16 +1824,16 @@ static void eval_weight(struct opstack **stack, const void *userdata)
|
|||
sprintf(buffer, "1 %s", LOC(lang, "weight_unit"));
|
||||
}
|
||||
else {
|
||||
sprintf(buffer, "%u %s", weight / SCALEWEIGHT, LOC(lang,
|
||||
sprintf(buffer, "%d %s", weight / SCALEWEIGHT, LOC(lang,
|
||||
"weight_unit_p"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (weight == 1) {
|
||||
sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT);
|
||||
sprintf(buffer, "1 %s %d", LOC(lang, "weight_per"), SCALEWEIGHT);
|
||||
}
|
||||
else {
|
||||
sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"),
|
||||
sprintf(buffer, "%d %s %d", weight, LOC(lang, "weight_per_p"),
|
||||
SCALEWEIGHT);
|
||||
}
|
||||
}
|
||||
|
@ -2136,7 +2124,6 @@ void register_reports(void)
|
|||
add_function("ship", &eval_ship);
|
||||
add_function("unit", &eval_unit);
|
||||
add_function("unit.dative", &eval_unit_dative);
|
||||
add_function("unit.name", &eval_unitname);
|
||||
add_function("unit.id", &eval_unitid);
|
||||
add_function("unit.size", &eval_unitsize);
|
||||
add_function("building", &eval_building);
|
||||
|
|
Loading…
Reference in a new issue