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 strongmen;
|
||||
int speeded = 0, speed = 1;
|
||||
bool pr_aid = false;
|
||||
int rest;
|
||||
const group *g = NULL;
|
||||
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) {
|
||||
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. */
|
||||
if (i < strongmen) {
|
||||
fig->person[i].damage += 2;
|
||||
|
@ -3631,18 +3622,22 @@ battle *make_battle(region * r)
|
|||
char zText[MAX_PATH];
|
||||
char zFilename[MAX_PATH];
|
||||
sprintf(zText, "%s/battles", basepath());
|
||||
_mkdir(zText);
|
||||
sprintf(zFilename, "%s/battle-%d-%s.log", zText, obs_count, simplename(r));
|
||||
bdebug = fopen(zFilename, "w");
|
||||
if (!bdebug)
|
||||
log_error("battles cannot be debugged\n");
|
||||
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));
|
||||
if (_mkdir(zText) != 0) {
|
||||
log_error("could not create subdirectory for battle logs: %s", zText);
|
||||
battledebug = false;
|
||||
}
|
||||
else {
|
||||
sprintf(zFilename, "%s/battle-%d-%s.log", zText, obs_count++, simplename(r));
|
||||
bdebug = fopen(zFilename, "w");
|
||||
if (!bdebug)
|
||||
log_error("battles cannot be debugged");
|
||||
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;
|
||||
|
@ -4259,9 +4254,10 @@ static bool is_enemy(battle *b, unit *u1, unit *u2) {
|
|||
for (es = b->sides; es != b->sides + b->nsides; ++es) {
|
||||
if (!s1 && es->faction == u1->faction) s1 = 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 {
|
||||
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 *target = (unit *)tolua_tousertype(L, 2, 0);
|
||||
const char *str = tolua_tostring(L, 3, 0);
|
||||
if (!target)
|
||||
if (!target) {
|
||||
tolua_error(L, TOLUA_CAST "target is nil", NULL);
|
||||
if (!sender)
|
||||
}
|
||||
else if (!sender) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -266,10 +270,13 @@ static int tolua_message_region(lua_State * L)
|
|||
{
|
||||
unit *sender = (unit *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
if (!sender)
|
||||
if (!sender) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -833,25 +833,29 @@ static void json_include(cJSON *json) {
|
|||
F = fopen(child->valuestring, "rt");
|
||||
}
|
||||
if (F) {
|
||||
cJSON *config;
|
||||
char *data;
|
||||
size_t sz;
|
||||
long pos;
|
||||
fseek(F, 0, SEEK_END);
|
||||
sz = ftell(F);
|
||||
pos = ftell(F);
|
||||
rewind(F);
|
||||
data = malloc(sz+1);
|
||||
sz = fread(data, 1, sz, F);
|
||||
data[sz] = 0;
|
||||
if (pos > 0) {
|
||||
cJSON *config;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
else {
|
||||
fscanf(F, "%d\n", &cturn);
|
||||
int c = fscanf(F, "%d\n", &cturn);
|
||||
fclose(F);
|
||||
if (c != 1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return cturn;
|
||||
}
|
||||
|
@ -1405,8 +1408,8 @@ int readgame(const char *filename, bool backup)
|
|||
fread(&gdata.version, sizeof(int), 1, F);
|
||||
if (gdata.version >= INTPAK_VERSION) {
|
||||
int stream_version;
|
||||
fread(&stream_version, sizeof(int), 1, F);
|
||||
assert(stream_version == STREAM_VERSION || !"unsupported data format");
|
||||
size_t sz = fread(&stream_version, sizeof(int), 1, F);
|
||||
assert((sz==1 && stream_version == STREAM_VERSION) || !"unsupported data format");
|
||||
}
|
||||
assert(gdata.version >= MIN_VERSION || !"unsupported data format");
|
||||
assert(gdata.version <= MAX_VERSION || !"unsupported data format");
|
||||
|
|
|
@ -4525,7 +4525,7 @@ void update_subscriptions(void)
|
|||
int subscription, fno;
|
||||
faction *f;
|
||||
|
||||
if (fscanf(F, "%d %s", &subscription, zFaction) <= 0)
|
||||
if (fscanf(F, "%d %4s", &subscription, zFaction) <= 0)
|
||||
break;
|
||||
fno = atoi36(zFaction);
|
||||
f = findfaction(fno);
|
||||
|
|
22
src/report.c
22
src/report.c
|
@ -1848,18 +1848,16 @@ const faction * f)
|
|||
{
|
||||
int i, bytes;
|
||||
const char *name, *bname, *billusion = NULL;
|
||||
const struct locale *lang = NULL;
|
||||
const struct locale *lang;
|
||||
char buffer[8192], *bufp = buffer;
|
||||
message *msg;
|
||||
size_t size = sizeof(buffer) - 1;
|
||||
|
||||
assert(f);
|
||||
lang = f->locale;
|
||||
newline(out);
|
||||
|
||||
if (f)
|
||||
lang = f->locale;
|
||||
|
||||
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);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
@ -1881,7 +1879,7 @@ const faction * f)
|
|||
}
|
||||
|
||||
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)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
|
@ -1889,7 +1887,7 @@ const faction * f)
|
|||
if (b->besieged > 0 && sr->mode >= see_lighthouse) {
|
||||
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
|
||||
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)
|
||||
WARN_STATIC_BUFFER();
|
||||
msg_release(msg);
|
||||
|
@ -1926,6 +1924,7 @@ static void nr_paragraph(stream *out, message * m, faction * f)
|
|||
char buf[4096], *bufp = buf;
|
||||
size_t size = sizeof(buf) - 1;
|
||||
|
||||
assert(f);
|
||||
bytes = (int)nr_render(m, f->locale, bufp, size, f);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
@ -2331,7 +2330,7 @@ const char *charset)
|
|||
message *m = 0;
|
||||
if (herb && lux) {
|
||||
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) {
|
||||
m = msg_message("nr_market_info_s", "p1",
|
||||
|
@ -2361,11 +2360,6 @@ const char *charset)
|
|||
newline(out);
|
||||
write_travelthru(out, r, f);
|
||||
}
|
||||
else if (sr->mode == see_lighthouse) {
|
||||
describe(out, sr, f);
|
||||
newline(out);
|
||||
write_travelthru(out, r, f);
|
||||
}
|
||||
else {
|
||||
describe(out, sr, f);
|
||||
newline(out);
|
||||
|
|
Loading…
Reference in a new issue