[PATCH 20/38] trace-cmd lib: check for a negative return value of read in tracecmd_compress_copy_from()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check that read() return a non negative value before adding it to all
in tracecmd_compress_copy_from(). If all == 1 before that, we would
exit the loops thinking it succeeded.

Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
---
 lib/trace-cmd/trace-compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index e550dbd4..3ca0e21f 100644
--- a/lib/trace-cmd/trace-compress.c
+++ b/lib/trace-cmd/trace-compress.c
@@ -714,10 +714,10 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
 
 		do {
 			r = read(fd, buf_from + all, rchunk - all);
-			all += r;
-
 			if (r <= 0)
 				break;
+
+			all += r;
 		} while (all != rchunk);
 
 
-- 
2.44.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux