From 38b252b2b3092d4c7df181563fce5a314d544441 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 27 Nov 2024 00:01:07 +0100 Subject: Added width spec, found by PVS-Studio --- FICS/ratings.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'FICS') diff --git a/FICS/ratings.c b/FICS/ratings.c index b5cd5a7..23b8b93 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -1471,7 +1471,9 @@ UpdateRank(int type, char *addName, statistics *sNew, char *delName) } while (fgets(line, sizeof line, fp) != NULL) { - sscanf(line, "%s %d %d %d", login, &sCur.rating, &sCur.num, + _Static_assert(ARRAY_SIZE(login) > 19, "'login' too small"); + + sscanf(line, "%19s %d %d %d", login, &sCur.rating, &sCur.num, &comp); if (delName != NULL && @@ -1542,7 +1544,9 @@ GetRank(FILE *fp, char *target, int countComp) while (fgets(line, sizeof line, fp) != NULL && !playerFound) { - sscanf(line, "%s %*d %d %d", login, &nGames, &is_computer); + _Static_assert(ARRAY_SIZE(login) > 19, "'login' too small"); + + sscanf(line, "%19s %*d %d %d", login, &nGames, &is_computer); if ((playerFound = !strcasecmp(login, target)) || CountRankLine(countComp, login, nGames, is_computer)) @@ -1571,7 +1575,10 @@ PositionFilePtr(FILE *fp, int count, int *last, int *nTied, int showComp) feof(fp) || ferror(fp)) break; - sscanf(line, "%s %d %d %d", login, &rating, &nGames, + + _Static_assert(ARRAY_SIZE(login) > 19, "'login' too small"); + + sscanf(line, "%19s %d %d %d", login, &rating, &nGames, &is_computer); } while (!CountRankLine(showComp, login, nGames, is_computer)); @@ -1604,7 +1611,10 @@ ShowRankEntry(int p, FILE *fp, int count, int comp, char *target, ferror(fp)) { findable = 0; } else if (newLine[0] != '\0') { - sscanf(newLine, "%s %d %d %d", login, &rating, + _Static_assert(ARRAY_SIZE(login) > 19, + "Assertion has failed"); + + sscanf(newLine, "%19s %d %d %d", login, &rating, &nGames, &is_comp); } else { login[0] = '\0'; -- cgit v1.2.3