From: Jan Hák Date: Thu, 18 Sep 2025 09:01:11 +0000 (+0200) Subject: contrib/files: fix stream error handling (clang analyzer) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=771c64c5a3ed2dbec0ea86732304806021ceb9ae;p=thirdparty%2Fknot-dns.git contrib/files: fix stream error handling (clang analyzer) POSIX / fread(): The file position indicator for the stream (if defined) shall be advanced by the number of bytes successfully read. If an error occurs, the resulting value of the file position indicator for the stream is unspecified. If a partial element is read, its value is unspecified. --- diff --git a/src/contrib/files.c b/src/contrib/files.c index 9fef720014..89a8186762 100644 --- a/src/contrib/files.c +++ b/src/contrib/files.c @@ -224,9 +224,11 @@ int copy_file(const char *dest, const char *src) goto done; } - ssize_t cnt; + assert(ret == 0); + size_t cnt; while ((cnt = fread(buf, sizeof(*buf), BUFSIZE, from)) != 0 && - (ret = (fwrite(buf, sizeof(*buf), cnt, file) == cnt))) { + (ret = (fwrite(buf, sizeof(*buf), cnt, file) == cnt)) && + (feof(from) | ferror(from)) == 0) { } ret = !ret || ferror(from);