diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-11-27 00:01:07 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-11-27 00:01:07 +0100 |
commit | 38b252b2b3092d4c7df181563fce5a314d544441 (patch) | |
tree | 2bcc79a2d5e8817d2ebfd4d55b58fb3473a4ae52 /FICS | |
parent | 56936d1c33d661e7ac6db4b68342bb26ea5534e1 (diff) |
Added width spec, found by PVS-Studio
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/ratings.c | 18 |
1 files changed, 14 insertions, 4 deletions
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'; |