diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-11-28 21:46:45 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-11-28 21:46:45 +0100 |
commit | bf0daae7f32422349d3365a428cf16cb700fdaef (patch) | |
tree | 7da696d3d259b730fecd8829af278ae70ca2124f /FICS | |
parent | a1db6a85e6c68a3cb8e49dd311634534db245249 (diff) |
Added width spec and fixed ignored retvals
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/makerank.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/FICS/makerank.c b/FICS/makerank.c index 8815a3c..daece45 100644 --- a/FICS/makerank.c +++ b/FICS/makerank.c @@ -46,6 +46,8 @@ GetPlayerInfo(char *fileName, ENTRY *e) } if (!strcmp(line, "v 1\n")) { + _Static_assert(ARRAY_SIZE(e->name) > 19, "Array too little"); + if (fgets(line, sizeof line, fp) == NULL || sscanf(line, "%19s", e->name) != 1) { warnx("%s: fgets() or sscanf() error", __func__); @@ -79,10 +81,24 @@ GetPlayerInfo(char *fileName, ENTRY *e) done = 1; } else { do { - sscanf(line, "%s", field); + _Static_assert(ARRAY_SIZE(field) > 19, + "Unexpected array length"); + _Static_assert(ARRAY_SIZE(NameWithCase) > 29, + "Unexpected array length"); + + if (sscanf(line, "%19s", field) != 1) { + warnx("%s: sscanf() error", __func__); + fclose(fp); + return 0; + } if (!strcmp(field, "Name:")) { - sscanf(line, "%*s %s", NameWithCase); + if (sscanf(line, "%*s %29s", NameWithCase) != 1) { + warnx("%s: expected name with case", + __func__); + fclose(fp); + return 0; + } if (strcasecmp(e->name, NameWithCase)) { printf("TROUBLE: %s's handle is " |