From e71182209be5870d31cc409a32e3d81f1641b00e Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 28 Feb 2016 17:02:09 +0200 Subject: random var crash when range is full uint32_t or full uint64_t --- src/stateless/cp/trex_stream_vm.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h index 4a0b1d59..58d43bd4 100644 --- a/src/stateless/cp/trex_stream_vm.h +++ b/src/stateless/cp/trex_stream_vm.h @@ -175,7 +175,7 @@ public: inline void run_rand(uint8_t * flow_var,uint32_t *per_thread_random) { uint32_t * p=(uint32_t *)(flow_var+m_flow_offset); - *p= m_min_val + (vm_rand32(per_thread_random) % (int)(m_max_val - m_min_val + 1)); + *p = m_min_val + (vm_rand32(per_thread_random) % ((uint64_t)(m_max_val) - m_min_val + 1)); } } __attribute__((packed)) ; @@ -208,7 +208,12 @@ public: inline void run_rand(uint8_t * flow_var,uint32_t *per_thread_random) { uint64_t * p=(uint64_t *)(flow_var+m_flow_offset); - *p= m_min_val + ( vm_rand64(per_thread_random) % (int)(m_max_val - m_min_val + 1)); + + if ((m_max_val - m_min_val) == UINT64_MAX) { + *p = vm_rand64(per_thread_random); + } else { + *p = m_min_val + ( vm_rand64(per_thread_random) % ( (uint64_t)m_max_val - m_min_val + 1) ); + } } -- cgit 1.2.3-korg