commit - 15533753e048b661f1ce4dcf124d427a447204bd
commit + 8e428ea30fd9f33f919c82c9b6f4b7380ebd2480
blob - 70dc529570f6ab7ce5a8aa2d1be53da697d5d7a0
blob + 4bdcce82e8c91adad5db7bdc48e1e024be6d8261
--- FICS/ratings.c
+++ FICS/ratings.c
return;
rating = nGames = is_computer = 0;
+ errno = 0;
rewind(fp);
+ if (errno) {
+ warn("%s: rewind", __func__);
+ return;
+ }
for (int i = 1; i < count; i++) {
do {
_Static_assert(ARRAY_SIZE(login) > 19,
"'login' too small");
- if (fgets(line, sizeof line, fp) == NULL ||
- feof(fp) ||
- ferror(fp))
+ if (feof(fp) || ferror(fp) ||
+ fgets(line, sizeof line, fp) == NULL)
break;
else if (sscanf(line, "%19s %d %d %d", login, &rating,
&nGames, &is_computer) != 4) {
}
} while (!CountRankLine(showComp, login, nGames, is_computer));
+ if (ferror(fp)) {
+ warnx("%s: the error indicator is set", __func__);
+ return;
+ }
+
if (rating != *last) {
*nTied = 1;
*last = rating;
// XXX
rating = 0;
- findable = (count > 0 && !feof(fp));
+ findable = (count > 0 && !feof(fp) && !ferror(fp));
nGames = 0;
is_comp = 0;