From 8f7f182c91124b3726b5bb76884381e9d9dbcb3b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 30 Oct 2015 12:55:30 +0100 Subject: [PATCH] CID 22507: Dereference null return value (NULL_RETURNS) checking fopen results --- src/creport.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/creport.c b/src/creport.c index 23f4f5671..9c2d2c423 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1705,23 +1705,26 @@ int crwritemap(const char *filename) FILE *F = fopen(filename, "w"); region *r; - fprintf(F, "VERSION %d\n", C_REPORT_VERSION); - fputs("\"UTF-8\";charset\n", F); + if (F) { + fprintf(F, "VERSION %d\n", C_REPORT_VERSION); + fputs("\"UTF-8\";charset\n", F); - for (r = regions; r; r = r->next) { - plane *pl = rplane(r); - int plid = plane_id(pl); - if (plid) { - fprintf(F, "REGION %d %d %d\n", r->x, r->y, plid); + for (r = regions; r; r = r->next) { + plane *pl = rplane(r); + int plid = plane_id(pl); + if (plid) { + fprintf(F, "REGION %d %d %d\n", r->x, r->y, plid); + } + else { + fprintf(F, "REGION %d %d\n", r->x, r->y); + } + fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale), + LOC(default_locale, terrain_name(r))); } - else { - fprintf(F, "REGION %d %d\n", r->x, r->y); - } - fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale), - LOC(default_locale, terrain_name(r))); + fclose(F); + return 0; } - fclose(F); - return 0; + return EOF; } void register_cr(void)