From 4bc5e260823db78bc3feeea1770d5aa564af45db Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 22 Dec 2023 21:47:48 -0500 Subject: [PATCH] static analyzer bit in files.c src/files.c(4403): warning: Reading invalid data from 'buf'. --- src/files.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/files.c b/src/files.c index 39c73a932..c3956deaa 100644 --- a/src/files.c +++ b/src/files.c @@ -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;