From 8bd157ea55d34a83002e58ad446f27ea970cd75f Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 2 Dec 2024 12:50:21 +0100 Subject: ReadGameAttrs: handle fgets() nullret --- FICS/gamedb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 3a5c50c..fce8ea3 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1333,7 +1333,7 @@ ReadGameAttrs(FILE *fp, char *fname, int g) { char *attr, *value; char line[MAX_GLINE_SIZE] = { '\0' }; - int len; + int len = 0; int version = 0; if (fgets(line, sizeof line, fp) == NULL) { @@ -1352,7 +1352,8 @@ ReadGameAttrs(FILE *fp, char *fname, int g) } else { do { if ((len = strlen(line)) <= 1) { - fgets(line, sizeof line, fp); + if (fgets(line, sizeof line, fp) == NULL) + break; continue; } @@ -1367,7 +1368,8 @@ ReadGameAttrs(FILE *fp, char *fname, int g) if (!*value) { fprintf(stderr, "FICS: Error reading file %s\n", fname); - fgets(line, sizeof line, fp); + if (fgets(line, sizeof line, fp) == NULL) + break; continue; } @@ -1378,7 +1380,8 @@ ReadGameAttrs(FILE *fp, char *fname, int g) if (!*value) { fprintf(stderr, "FICS: Error reading file %s\n", fname); - fgets(line, sizeof line, fp); + if (fgets(line, sizeof line, fp) == NULL) + break; continue; } @@ -1387,7 +1390,8 @@ ReadGameAttrs(FILE *fp, char *fname, int g) if (got_attr_value(g, attr, value, fp, fname)) return -1; - fgets(line, sizeof line, fp); + if (fgets(line, sizeof line, fp) == NULL) + break; } while (!feof(fp)); } -- cgit v1.2.3