forked from github/server
Merge branch 'ennorehling-coverity-scan' into develop
This commit is contained in:
commit
05ff554053
6 changed files with 66 additions and 62 deletions
40
src/battle.c
40
src/battle.c
|
@ -3247,7 +3247,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
int berserk;
|
int berserk;
|
||||||
int strongmen;
|
int strongmen;
|
||||||
int speeded = 0, speed = 1;
|
int speeded = 0, speed = 1;
|
||||||
bool pr_aid = false;
|
|
||||||
int rest;
|
int rest;
|
||||||
const group *g = NULL;
|
const group *g = NULL;
|
||||||
const attrib *a = a_find(u->attribs, &at_otherfaction);
|
const attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||||
|
@ -3348,14 +3347,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
if (i < berserk) {
|
if (i < berserk) {
|
||||||
fig->person[i].attack++;
|
fig->person[i].attack++;
|
||||||
}
|
}
|
||||||
/* Leute mit einem Aid-Prayer bekommen +1 auf fast alles. */
|
|
||||||
if (pr_aid) {
|
|
||||||
fig->person[i].attack++;
|
|
||||||
fig->person[i].defence++;
|
|
||||||
fig->person[i].damage++;
|
|
||||||
fig->person[i].damage_rear++;
|
|
||||||
fig->person[i].flags |= FL_COURAGE;
|
|
||||||
}
|
|
||||||
/* Leute mit Kraftzauber machen +2 Schaden im Nahkampf. */
|
/* Leute mit Kraftzauber machen +2 Schaden im Nahkampf. */
|
||||||
if (i < strongmen) {
|
if (i < strongmen) {
|
||||||
fig->person[i].damage += 2;
|
fig->person[i].damage += 2;
|
||||||
|
@ -3631,18 +3622,22 @@ battle *make_battle(region * r)
|
||||||
char zText[MAX_PATH];
|
char zText[MAX_PATH];
|
||||||
char zFilename[MAX_PATH];
|
char zFilename[MAX_PATH];
|
||||||
sprintf(zText, "%s/battles", basepath());
|
sprintf(zText, "%s/battles", basepath());
|
||||||
_mkdir(zText);
|
if (_mkdir(zText) != 0) {
|
||||||
sprintf(zFilename, "%s/battle-%d-%s.log", zText, obs_count, simplename(r));
|
log_error("could not create subdirectory for battle logs: %s", zText);
|
||||||
bdebug = fopen(zFilename, "w");
|
battledebug = false;
|
||||||
if (!bdebug)
|
}
|
||||||
log_error("battles cannot be debugged\n");
|
else {
|
||||||
else {
|
sprintf(zFilename, "%s/battle-%d-%s.log", zText, obs_count++, simplename(r));
|
||||||
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
bdebug = fopen(zFilename, "w");
|
||||||
fwrite(utf8_bom, 1, 3, bdebug);
|
if (!bdebug)
|
||||||
fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r,
|
log_error("battles cannot be debugged");
|
||||||
default_locale));
|
else {
|
||||||
|
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
||||||
|
fwrite(utf8_bom, 1, 3, bdebug);
|
||||||
|
fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r,
|
||||||
|
default_locale));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
obs_count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b->region = r;
|
b->region = r;
|
||||||
|
@ -4259,9 +4254,10 @@ static bool is_enemy(battle *b, unit *u1, unit *u2) {
|
||||||
for (es = b->sides; es != b->sides + b->nsides; ++es) {
|
for (es = b->sides; es != b->sides + b->nsides; ++es) {
|
||||||
if (!s1 && es->faction == u1->faction) s1 = es;
|
if (!s1 && es->faction == u1->faction) s1 = es;
|
||||||
else if (!s2 && es->faction == u2->faction) s2 = es;
|
else if (!s2 && es->faction == u2->faction) s2 = es;
|
||||||
if (s1 && s2) break;
|
if (s1 && s2) {
|
||||||
|
return enemy(s1, s2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return enemy(s1, s2);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return !help_enter(u1, u2);
|
return !help_enter(u1, u2);
|
||||||
|
|
|
@ -237,11 +237,15 @@ static int tolua_message_unit(lua_State * L)
|
||||||
unit *sender = (unit *)tolua_tousertype(L, 1, 0);
|
unit *sender = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit *target = (unit *)tolua_tousertype(L, 2, 0);
|
unit *target = (unit *)tolua_tousertype(L, 2, 0);
|
||||||
const char *str = tolua_tostring(L, 3, 0);
|
const char *str = tolua_tostring(L, 3, 0);
|
||||||
if (!target)
|
if (!target) {
|
||||||
tolua_error(L, TOLUA_CAST "target is nil", NULL);
|
tolua_error(L, TOLUA_CAST "target is nil", NULL);
|
||||||
if (!sender)
|
}
|
||||||
|
else if (!sender) {
|
||||||
tolua_error(L, TOLUA_CAST "sender is nil", NULL);
|
tolua_error(L, TOLUA_CAST "sender is nil", NULL);
|
||||||
deliverMail(target->faction, sender->region, sender, str, target);
|
}
|
||||||
|
else {
|
||||||
|
deliverMail(target->faction, sender->region, sender, str, target);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,10 +270,13 @@ static int tolua_message_region(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *sender = (unit *)tolua_tousertype(L, 1, 0);
|
unit *sender = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *str = tolua_tostring(L, 2, 0);
|
const char *str = tolua_tostring(L, 2, 0);
|
||||||
if (!sender)
|
if (!sender) {
|
||||||
tolua_error(L, TOLUA_CAST "sender is nil", NULL);
|
tolua_error(L, TOLUA_CAST "sender is nil", NULL);
|
||||||
ADDMSG(&sender->region->msgs, msg_message("mail_result", "unit message",
|
}
|
||||||
sender, str));
|
else {
|
||||||
|
ADDMSG(&sender->region->msgs, msg_message("mail_result", "unit message",
|
||||||
|
sender, str));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -833,25 +833,29 @@ static void json_include(cJSON *json) {
|
||||||
F = fopen(child->valuestring, "rt");
|
F = fopen(child->valuestring, "rt");
|
||||||
}
|
}
|
||||||
if (F) {
|
if (F) {
|
||||||
cJSON *config;
|
long pos;
|
||||||
char *data;
|
|
||||||
size_t sz;
|
|
||||||
fseek(F, 0, SEEK_END);
|
fseek(F, 0, SEEK_END);
|
||||||
sz = ftell(F);
|
pos = ftell(F);
|
||||||
rewind(F);
|
rewind(F);
|
||||||
data = malloc(sz+1);
|
if (pos > 0) {
|
||||||
sz = fread(data, 1, sz, F);
|
cJSON *config;
|
||||||
data[sz] = 0;
|
char *data;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
|
data = malloc(pos + 1);
|
||||||
|
sz = fread(data, 1, (size_t)pos, F);
|
||||||
|
data[sz] = 0;
|
||||||
|
config = cJSON_Parse(data);
|
||||||
|
free(data);
|
||||||
|
if (config) {
|
||||||
|
json_config(config);
|
||||||
|
cJSON_Delete(config);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_error("invalid JSON, could not parse %s", child->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
config = cJSON_Parse(data);
|
|
||||||
free(data);
|
|
||||||
if (config) {
|
|
||||||
json_config(config);
|
|
||||||
cJSON_Delete(config);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log_error("invalid JSON, could not parse %s", child->valuestring);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -553,8 +553,11 @@ int current_turn(void)
|
||||||
perror(zText);
|
perror(zText);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fscanf(F, "%d\n", &cturn);
|
int c = fscanf(F, "%d\n", &cturn);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
|
if (c != 1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cturn;
|
return cturn;
|
||||||
}
|
}
|
||||||
|
@ -1405,8 +1408,8 @@ int readgame(const char *filename, bool backup)
|
||||||
fread(&gdata.version, sizeof(int), 1, F);
|
fread(&gdata.version, sizeof(int), 1, F);
|
||||||
if (gdata.version >= INTPAK_VERSION) {
|
if (gdata.version >= INTPAK_VERSION) {
|
||||||
int stream_version;
|
int stream_version;
|
||||||
fread(&stream_version, sizeof(int), 1, F);
|
size_t sz = fread(&stream_version, sizeof(int), 1, F);
|
||||||
assert(stream_version == STREAM_VERSION || !"unsupported data format");
|
assert((sz==1 && stream_version == STREAM_VERSION) || !"unsupported data format");
|
||||||
}
|
}
|
||||||
assert(gdata.version >= MIN_VERSION || !"unsupported data format");
|
assert(gdata.version >= MIN_VERSION || !"unsupported data format");
|
||||||
assert(gdata.version <= MAX_VERSION || !"unsupported data format");
|
assert(gdata.version <= MAX_VERSION || !"unsupported data format");
|
||||||
|
|
|
@ -4525,7 +4525,7 @@ void update_subscriptions(void)
|
||||||
int subscription, fno;
|
int subscription, fno;
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
if (fscanf(F, "%d %s", &subscription, zFaction) <= 0)
|
if (fscanf(F, "%d %4s", &subscription, zFaction) <= 0)
|
||||||
break;
|
break;
|
||||||
fno = atoi36(zFaction);
|
fno = atoi36(zFaction);
|
||||||
f = findfaction(fno);
|
f = findfaction(fno);
|
||||||
|
|
22
src/report.c
22
src/report.c
|
@ -1848,18 +1848,16 @@ const faction * f)
|
||||||
{
|
{
|
||||||
int i, bytes;
|
int i, bytes;
|
||||||
const char *name, *bname, *billusion = NULL;
|
const char *name, *bname, *billusion = NULL;
|
||||||
const struct locale *lang = NULL;
|
const struct locale *lang;
|
||||||
char buffer[8192], *bufp = buffer;
|
char buffer[8192], *bufp = buffer;
|
||||||
message *msg;
|
message *msg;
|
||||||
size_t size = sizeof(buffer) - 1;
|
size_t size = sizeof(buffer) - 1;
|
||||||
|
|
||||||
|
assert(f);
|
||||||
|
lang = f->locale;
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
||||||
if (f)
|
|
||||||
lang = f->locale;
|
|
||||||
|
|
||||||
bytes =
|
bytes =
|
||||||
_snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(f->locale,
|
_snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang,
|
||||||
"nr_size"), b->size);
|
"nr_size"), b->size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
@ -1881,7 +1879,7 @@ const faction * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->size < b->type->maxsize) {
|
if (b->size < b->type->maxsize) {
|
||||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_building_inprogress"), size);
|
bytes = (int)strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
|
@ -1889,7 +1887,7 @@ const faction * f)
|
||||||
if (b->besieged > 0 && sr->mode >= see_lighthouse) {
|
if (b->besieged > 0 && sr->mode >= see_lighthouse) {
|
||||||
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
|
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
|
||||||
b->besieged - b->size * SIEGEFACTOR);
|
b->besieged - b->size * SIEGEFACTOR);
|
||||||
bytes = (int)nr_render(msg, f->locale, bufp, size, f);
|
bytes = (int)nr_render(msg, lang, bufp, size, f);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
@ -1926,6 +1924,7 @@ static void nr_paragraph(stream *out, message * m, faction * f)
|
||||||
char buf[4096], *bufp = buf;
|
char buf[4096], *bufp = buf;
|
||||||
size_t size = sizeof(buf) - 1;
|
size_t size = sizeof(buf) - 1;
|
||||||
|
|
||||||
|
assert(f);
|
||||||
bytes = (int)nr_render(m, f->locale, bufp, size, f);
|
bytes = (int)nr_render(m, f->locale, bufp, size, f);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
@ -2331,7 +2330,7 @@ const char *charset)
|
||||||
message *m = 0;
|
message *m = 0;
|
||||||
if (herb && lux) {
|
if (herb && lux) {
|
||||||
m = msg_message("nr_market_info_p", "p1 p2",
|
m = msg_message("nr_market_info_p", "p1 p2",
|
||||||
lux ? lux->rtype : 0, herb ? herb->rtype : 0);
|
lux->rtype, herb->rtype);
|
||||||
}
|
}
|
||||||
else if (lux || herb) {
|
else if (lux || herb) {
|
||||||
m = msg_message("nr_market_info_s", "p1",
|
m = msg_message("nr_market_info_s", "p1",
|
||||||
|
@ -2361,11 +2360,6 @@ const char *charset)
|
||||||
newline(out);
|
newline(out);
|
||||||
write_travelthru(out, r, f);
|
write_travelthru(out, r, f);
|
||||||
}
|
}
|
||||||
else if (sr->mode == see_lighthouse) {
|
|
||||||
describe(out, sr, f);
|
|
||||||
newline(out);
|
|
||||||
write_travelthru(out, r, f);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
describe(out, sr, f);
|
describe(out, sr, f);
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
Loading…
Reference in a new issue