static analyzer bit in files.c

src/files.c(4403): warning: Reading invalid data from 'buf'.
This commit is contained in:
nhmall
2023-12-22 21:47:48 -05:00
parent 7a533a911c
commit 4bc5e26082

View File

@@ -4396,12 +4396,14 @@ boolean
copy_bytes(int ifd, int ofd)
{
char buf[BUFSIZ];
int nfrom, nto;
int nfrom, nto = 0;
do {
nfrom = read(ifd, buf, BUFSIZ);
nto = write(ofd, buf, nfrom);
if (nto != nfrom)
/* read can return -1 */
if (nfrom >= 0 && nfrom <= BUFSIZ)
nto = write(ofd, buf, nfrom);
if (nto != nfrom || nfrom < 0)
return FALSE;
} while (nfrom == BUFSIZ);
return TRUE;