diff mbox series

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

Message ID 20240605134054.2626953-21-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit c5df2625149cfbaf1aefd0fbacebea4a06830c6d
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
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@redhat.com>
---
 lib/trace-cmd/trace-compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

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);