From c5a9716e18dbfdab7a21f12ca6a608ac71927b7b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 23 Nov 2024 18:48:11 +0100 Subject: pgames: fscanf: added width spec (found by PVS-Studio) --- FICS/gamedb.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 0d65328..9514c91 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -2047,7 +2047,7 @@ pgames(int p, int p1, char *fname) char OppName[MAX_LOGIN_NAME + 1] = { '\0' }; char eco[100] = { '\0' }; char ending[100] = { '\0' }; - char result[2] = { 0,0 }; + char result[2] = { 0,0 }; // XXX: right size? char type[100] = { '\0' }; int MyRating, OppRating; int count; @@ -2063,8 +2063,16 @@ pgames(int p, int p1, char *fname) pprintf(p, " Opponent Type " "ECO End Date\n"); + _Static_assert(ARRAY_SIZE(result) > 1, "'result' too small"); + _Static_assert(ARRAY_SIZE(MyColor) > 1, "'MyColor' too small"); + _Static_assert(ARRAY_SIZE(OppName) > 19, "'OppName' too small"); + _Static_assert(ARRAY_SIZE(type) > 99, "'type' too small"); + _Static_assert(ARRAY_SIZE(eco) > 99, "'eco' too small"); + _Static_assert(ARRAY_SIZE(ending) > 99, "'ending' too small"); + while (!feof(fp)) { - if (fscanf(fp, "%d %s %d %s %d %s %s %d %d %d %d %s %s %ld\n", + if (fscanf(fp, "%d %1s %d %1s %d %19s %99s %d %d %d %d %99s " + "%99s %ld\n", &count, result, &MyRating, MyColor, &OppRating, OppName, type, -- cgit v1.2.3