From: Christian Heller Date: Wed, 21 Aug 2013 03:14:20 +0000 (+0200) Subject: In save_game(), error-exit on earliest of writing errors, not after cascade of them. X-Git-Tag: tce~1084 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/process?a=commitdiff_plain;h=b4d3dd91f438b97be97afa51e7a0c208f1ae475b;p=plomrogue In save_game(), error-exit on earliest of writing errors, not after cascade of them. --- diff --git a/src/misc.c b/src/misc.c index 9063fef..1edd7d2 100644 --- a/src/misc.c +++ b/src/misc.c @@ -136,16 +136,17 @@ extern void save_game(struct World * world) FILE * file = fopen("savefile", "w"); exit_err(0 == file, world, "Error saving game: Unable to open savefile for writing."); - uint8_t err; - err = write_uint32_bigendian(world->seed, file); - err = err | write_uint32_bigendian(world->turn, file); - err = err | write_uint16_bigendian(world->player->pos.y + 1, file); - err = err | write_uint16_bigendian(world->player->pos.x + 1, file); - err = err | write_uint8(world->player->hitpoints, file); - err = err | write_map_objects(world, world->monster, file); - err = err | write_map_objects(world, world->item, file); - exit_err(err, world, - "Error saving game: Trouble writing to opened savefile."); + if ( write_uint32_bigendian(world->seed, file) + || write_uint32_bigendian(world->turn, file) + || write_uint16_bigendian(world->player->pos.y + 1, file) + || write_uint16_bigendian(world->player->pos.x + 1, file) + || write_uint8(world->player->hitpoints, file) + || write_map_objects(world, world->monster, file) + || write_map_objects(world, world->item, file)) + { + exit_err(1, world, + "Error saving game: Trouble writing to opened savefile."); + } exit_err(fclose(file), world, "Error saving game: Unable to close opened savefile."); }