diff mbox

[perftest,18/23] perftest_resources: do 64-bit math setting tarr_size

Message ID 1471541538-20270-19-git-send-email-jarod@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jarod Wilson Aug. 18, 2016, 5:32 p.m. UTC
Error: OVERFLOW_BEFORE_WIDEN: [#def28]
perftest-3.0/src/perftest_resources.c:650: overflow_before_widen: Potentially overflowing expression "user_param->iters * user_param->num_of_qps" with type "int" (32 bits, signed) is evaluated
using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).
perftest-3.0/src/perftest_resources.c:650: remediation: To avoid overflow, cast either "user_param->iters" or "user_param->num_of_qps" to type "uint64_t".

CC: Gil Rockah <gilr@mellanox.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 src/perftest_resources.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox

Patch

diff --git a/src/perftest_resources.c b/src/perftest_resources.c
index 91c6d1e..7e982e9 100755
--- a/src/perftest_resources.c
+++ b/src/perftest_resources.c
@@ -650,7 +650,7 @@  void alloc_ctx(struct pingpong_context *ctx,struct perftest_parameters *user_par
 
 	ALLOCATE(user_param->port_by_qp, uint64_t, user_param->num_of_qps);
 
-	tarr_size = (user_param->noPeak) ? 1 : user_param->iters*user_param->num_of_qps;
+	tarr_size = (user_param->noPeak) ? 1UL : (uint64_t)user_param->iters*user_param->num_of_qps;
 	ALLOCATE(user_param->tposted, cycles_t, tarr_size);
 	memset(user_param->tposted, 0, sizeof(cycles_t)*tarr_size);