From f8198ee7eadb3a70c2e7146069b424363306888f Mon Sep 17 00:00:00 2001 From: Tim Wickberg <tim@schedmd.com> Date: Tue, 15 Mar 2016 12:31:42 -0400 Subject: [PATCH] Fix compression calculation again. Fix bad cast in 3a604563c, and update pct to 64-bits to prevent truncation of intermediate value (pct * 100). --- src/bcast/file_bcast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bcast/file_bcast.c b/src/bcast/file_bcast.c index 9376c938e2c..89f0147fe69 100644 --- a/src/bcast/file_bcast.c +++ b/src/bcast/file_bcast.c @@ -433,7 +433,7 @@ static int _bcast_file(struct bcast_parameters *params) xfree(buffer); if (size_uncompressed && params->compress != 0) { - int32_t pct = (int32_t)(size_uncompressed - size_compressed); + int64_t pct = (int64_t) size_uncompressed - size_compressed; /* Dividing a negative by a positive in C99 results in * "truncation towards zero" which gives unexpected values for * pct. This construct avoids that problem. @@ -441,7 +441,7 @@ static int _bcast_file(struct bcast_parameters *params) pct = (pct>=0) ? pct * 100 / size_uncompressed : - (-pct * 100 / size_uncompressed); verbose("File compressed from %u to %u (%d percent) in %u usec", - size_uncompressed, size_compressed, pct, + size_uncompressed, size_compressed, (int) pct, time_compression); } -- GitLab