fix highly theoretical source of crash.

bind_eressea now checks if bindings were called without filename
This commit is contained in:
Enno Rehling 2021-03-15 20:00:58 +01:00
parent 56141ee7a1
commit 36653ec65b
2 changed files with 44 additions and 31 deletions

View File

@ -28,52 +28,65 @@ void eressea_free_game(void) {
} }
int eressea_read_game(const char * filename) { int eressea_read_game(const char * filename) {
return readgame(filename); if (filename) {
return readgame(filename);
}
return -1;
} }
int eressea_write_game(const char * filename) { int eressea_write_game(const char * filename) {
remove_empty_factions(); if (filename) {
return writegame(filename); remove_empty_factions();
return writegame(filename);
}
return -1;
} }
int eressea_read_orders(const char * filename) { int eressea_read_orders(const char * filename) {
FILE * F = fopen(filename, "r"); if (filename) {
int result; FILE *F = fopen(filename, "r");
int result;
if (!F) { if (!F) {
perror(filename); perror(filename);
return -1; return -1;
}
log_info("reading orders from %s", filename);
result = parseorders(F);
fclose(F);
return result;
} }
log_info("reading orders from %s", filename); return -1;
result = parseorders(F);
fclose(F);
return result;
} }
int eressea_export_json(const char * filename, int flags) { int eressea_export_json(const char * filename, int flags) {
FILE *F = fopen(filename, "w"); if (filename) {
if (F) { FILE *F = fopen(filename, "w");
stream out = { 0 }; if (F) {
int err; stream out = { 0 };
fstream_init(&out, F); int err;
err = json_export(&out, flags); fstream_init(&out, F);
fstream_done(&out); err = json_export(&out, flags);
return err; fstream_done(&out);
return err;
}
perror(filename);
} }
perror(filename);
return -1; return -1;
} }
int eressea_import_json(const char * filename) { int eressea_import_json(const char * filename) {
FILE *F = fopen(filename, "r"); if (filename) {
if (F) { FILE *F = fopen(filename, "r");
stream out = { 0 }; if (F) {
int err; stream out = { 0 };
fstream_init(&out, F); int err;
err = json_import(&out); fstream_init(&out, F);
fstream_done(&out); err = json_import(&out);
return err; fstream_done(&out);
return err;
}
perror(filename);
} }
perror(filename);
return -1; return -1;
} }

View File

@ -80,7 +80,7 @@ int volcano_damage(unit* u, const char* dice)
{ {
int hp = u->hp / u->number; int hp = u->hp / u->number;
int remain = u->hp % u->number; int remain = u->hp % u->number;
int ac, i, dead = 0, total = 0; int ac = 0, i, dead = 0, total = 0;
int healings = 0; int healings = 0;
const struct race* rc_cat = get_race(RC_CAT); const struct race* rc_cat = get_race(RC_CAT);
int protect = inside_building(u) ? (building_protection(u->building) + 1) : 0; int protect = inside_building(u) ? (building_protection(u->building) + 1) : 0;