diff options
| author | Markus Uhlin <markus@nifty-networks.net> | 2026-03-08 10:43:19 +0100 |
|---|---|---|
| committer | Markus Uhlin <markus@nifty-networks.net> | 2026-03-08 10:43:19 +0100 |
| commit | 4638ca61e176bfcbdb28e696dbfa0834c5583d98 (patch) | |
| tree | f9a9b287b6f65d06685d2f817b3753df8f0f7853 /FICS | |
| parent | 8735e1f1b25ed0f9cd61e276d2f42bd5ed714ff2 (diff) | |
save_ratings: fixed unchecked function return values
Diffstat (limited to 'FICS')
| -rw-r--r-- | FICS/ratings.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/FICS/ratings.c b/FICS/ratings.c index 3519db9..0ecb358 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -416,8 +416,9 @@ save_ratings(void) FILE *fp; char fname[MAX_FILENAME_SIZE] = { '\0' }; int fd; + int ret[5]; - snprintf(fname, sizeof fname, "%s/newratingsV%d_data", stats_dir, + (void) snprintf(fname, sizeof fname, "%s/newratingsV%d_data", stats_dir, STATS_VERSION); if ((fd = open(fname, g_open_flags[OPFL_WRITE], g_open_modes)) < 0) { @@ -425,21 +426,33 @@ save_ratings(void) return; } else if ((fp = fdopen(fd, "w")) == NULL) { warn("%s: can't write ratings data", __func__); - close(fd); + + if (close(fd) != 0) + warn("%s: close() error", __func__); + return; } - fprintf(fp, "%10f %10f %10f %d\n", Rb_M, Rb_S, Rb_total, Rb_count); - fprintf(fp, "%10f %10f %10f %d\n", Rs_M, Rs_S, Rs_total, Rs_count); - fprintf(fp, "%10f %10f %10f %d\n", Rw_M, Rw_S, Rw_total, Rw_count); - fprintf(fp, "%10f %10f %10f %d\n", Rl_M, Rl_S, Rl_total, Rl_count); + ret[0] = fprintf(fp, "%10f %10f %10f %d\n", Rb_M, Rb_S, Rb_total, Rb_count); + ret[1] = fprintf(fp, "%10f %10f %10f %d\n", Rs_M, Rs_S, Rs_total, Rs_count); + ret[2] = fprintf(fp, "%10f %10f %10f %d\n", Rw_M, Rw_S, Rw_total, Rw_count); + ret[3] = fprintf(fp, "%10f %10f %10f %d\n", Rl_M, Rl_S, Rl_total, Rl_count); + + if (ret[0] < 0 || ret[1] < 0 || ret[2] < 0 || ret[3] < 0) + warnx("%s: error writing to file", __func__); for (int i = 0; i < MAXHIST; i++) { - fprintf(fp, "%d %d %d %d\n", sHist[i], bHist[i], wHist[i], - lHist[i]); + ret[4] = fprintf(fp, "%d %d %d %d\n", sHist[i], bHist[i], + wHist[i], lHist[i]); + if (ret[4] < 0) { + warnx("%s: error writing to file (in the loop)", + __func__); + break; + } } - fclose(fp); + if (fclose(fp) != 0) + warn("%s: fclose() error", __func__); } PRIVATE void |
