aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/playerdb.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-31 22:46:49 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-31 22:46:49 +0100
commitfa9551a286073acff5b0178380868e3ed7a1b6f5 (patch)
tree8c87210d16930d9b006c9d207a93192cb1c2880a /FICS/playerdb.c
parent8bcfa8db8a604ed9d0cde07bb20bf8089362c3e9 (diff)
Check the return of fgets() and trim the newline using strcspn()
Diffstat (limited to 'FICS/playerdb.c')
-rw-r--r--FICS/playerdb.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/FICS/playerdb.c b/FICS/playerdb.c
index 065d1d2..01edb3c 100644
--- a/FICS/playerdb.c
+++ b/FICS/playerdb.c
@@ -431,9 +431,13 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version)
pp->l_stats.sterr = (ls / 10.0);
pp->bug_stats.sterr = (bugs / 10.0);
- fgets(tmp2, sizeof tmp2, fp);
- tmp2[strlen(tmp2) - 1] = '\0';
- pp->prompt = xstrdup(tmp2);
+ if (fgets(tmp2, sizeof tmp2, fp) == NULL) {
+ fprintf(stderr, "Player %s is corrupt\n", parray[p].name);
+ return;
+ } else {
+ tmp2[strcspn(tmp2, "\n")] = '\0';
+ pp->prompt = xstrdup(tmp2);
+ }
if (fscanf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d "
"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",