From 523224ecb31e716cb0fa6db31ee9b68f118f7fcd Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 2 Dec 2024 13:51:09 +0100 Subject: Improved old_mail_moves() --- FICS/obsproc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'FICS') diff --git a/FICS/obsproc.c b/FICS/obsproc.c index 4dd7b2d..08b4796 100644 --- a/FICS/obsproc.c +++ b/FICS/obsproc.c @@ -672,11 +672,11 @@ com_mailmoves(int p, param_list param) PRIVATE int old_mail_moves(int p, int mail, param_list param) { - FILE *fp; + FILE *fp = NULL; char fname[MAX_FILENAME_SIZE] = { '\0' }; char tmp[2048] = { '\0' }; char *ptmp = tmp; - int count; + int count = 0; int p1, connected; if (mail && (!parray[p].registered)) { @@ -705,10 +705,16 @@ old_mail_moves(int p, int mail, param_list param) return COM_OK; } - while (!feof(fp)) - fgets(tmp, 1024, fp); + while (fgets(tmp, sizeof tmp, fp) != NULL) { + /* null */; + } + + if (sscanf(ptmp, "%d", &count) != 1) { + warnx("%s: sscanf() error", __func__); + fclose(fp); + return COM_FAILED; + } - sscanf(ptmp, "%d", &count); fclose(fp); pprintf(p, "Last game for %s was history game %d.\n", parray[p1].name, count); -- cgit v1.2.3