From 2f486e199529a456f7dcdc5c9eb5b82c2727fed1 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 7 Mar 2026 17:38:29 +0100 Subject: Improved psend_logoutfile() --- FICS/utils.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/FICS/utils.c b/FICS/utils.c index 679aa08..e2193ce 100644 --- a/FICS/utils.c +++ b/FICS/utils.c @@ -579,23 +579,29 @@ psend_logoutfile(int p, char *dir, char *file) char fname[MAX_FILENAME_SIZE] = { '\0' }; char tmp[MAX_LINE_SIZE] = { '\0' }; + if (file == NULL || strcmp(file, "") == 0) { + warnx("%s: error: no file", __func__); + return -1; + } + if (parray[p].last_file) rfree(parray[p].last_file); parray[p].last_file = NULL; parray[p].last_file_byte = 0L; if (dir) - snprintf(fname, sizeof fname, "%s/%s", dir, file); + (void) snprintf(fname, sizeof fname, "%s/%s", dir, file); else - strlcpy(fname, file, sizeof fname); + (void) strlcpy(fname, file, sizeof fname); if ((fp = fopen(fname, "r")) == NULL) return -1; - while (fgets(tmp, sizeof tmp, fp) != NULL && !feof(fp)) + while (fgets(tmp, sizeof tmp, fp) != NULL) net_send_string(parray[p].socket, tmp, 1); - fclose(fp); + if (fclose(fp) != 0) + warn("%s: fclose() error", __func__); return 0; } -- cgit v1.2.3