summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-02-28 17:02:09 +0200
committerimarom <imarom@cisco.com>2016-02-29 09:43:45 +0200
commite71182209be5870d31cc409a32e3d81f1641b00e (patch)
treedf808ecbd3e5e25638fb5bb2e749e2c4f8ebc052 /src
parenta9c35eacd8caebe65e8c685f9285740b2764ea21 (diff)
random var crash when range is full uint32_t or full uint64_t
Diffstat (limited to 'src')
-rw-r--r--src/stateless/cp/trex_stream_vm.h9
1 files changed, 7 insertions, 2 deletions
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) );
+ }
}