Skip to content

Commit 6f68012

Browse files
committed
Do not call srand before each rand
It should only be called once, to initialize the seed. Otherwise, all values returned by rand() will be the same.
1 parent 9bf7a0d commit 6f68012

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

test/malloc_compliance_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ using umf_test::test;
3333
//------------------------------------------------------------------------
3434

3535
static inline size_t rand_alloc_size(int max) {
36-
srand(SRAND_INIT_VALUE);
3736
return rand() % max;
3837
}
3938

@@ -50,6 +49,7 @@ static inline void free_memory(umf_memory_pool_handle_t hPool,
5049

5150
// ISO/IEC 9899:TC3 7.20.3.3
5251
void malloc_compliance_test(umf_memory_pool_handle_t hPool) {
52+
srand(SRAND_INIT_VALUE);
5353
void *alloc_ptr[ITERATIONS];
5454
size_t alloc_ptr_size[ITERATIONS];
5555

@@ -80,6 +80,7 @@ void malloc_compliance_test(umf_memory_pool_handle_t hPool) {
8080

8181
// ISO/IEC 9899:TC3 7.20.3.1
8282
void calloc_compliance_test(umf_memory_pool_handle_t hPool) {
83+
srand(SRAND_INIT_VALUE);
8384
void *alloc_ptr[ITERATIONS];
8485
size_t alloc_size;
8586

@@ -98,6 +99,7 @@ void calloc_compliance_test(umf_memory_pool_handle_t hPool) {
9899

99100
// ISO/IEC 9899:TC3 7.20.3.4
100101
void realloc_compliance_test(umf_memory_pool_handle_t hPool) {
102+
srand(SRAND_INIT_VALUE);
101103
// If ptr is a null pointer, the realloc function behaves
102104
// like the malloc function for the specified size
103105
void *ret = umfPoolRealloc(hPool, NULL, 10);

0 commit comments

Comments
 (0)