From 93925a1a0c36a819294d7f2281260532e3330b6a Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 23 Nov 2024 09:42:42 +0100 Subject: Improved rscan_news() --- FICS/command.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'FICS') diff --git a/FICS/command.c b/FICS/command.c index 872c92c..88aae2e 100644 --- a/FICS/command.c +++ b/FICS/command.c @@ -708,12 +708,17 @@ rscan_news(FILE *fp, int p, int lc) long int lval = 0; time_t crtime = 0; - fgets(junk, MAX_LINE_SIZE, fp); + if (fgets(junk, sizeof junk, fp) == NULL || + feof(fp)) + return; + + _Static_assert(ARRAY_SIZE(count) > 9, "Unexpected array size"); - if (feof(fp)) + if (sscanf(junk, "%ld %9s", &lval, count) != 2) { + warnx("%s: sscanf() error: too few items", __func__); return; + } - sscanf(junk, "%ld %s", &lval, count); crtime = lval; if ((crtime - lc) < 0) -- cgit v1.2.3