mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-10-26 14:16:33 +01:00 
			
		
		
		
	memtag_test: remove usages of rand()
It didn't work correctly due to not being seeded and its usage wasn't necessary.
This commit is contained in:
		
							parent
							
								
									c5ad7ecedc
								
							
						
					
					
						commit
						14f4e927ca
					
				
					 1 changed files with 3 additions and 22 deletions
				
			
		|  | @ -36,21 +36,6 @@ void *untag_pointer(void *ptr) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void tag_distinctness() { | void tag_distinctness() { | ||||||
|     if (rand() & 1) { |  | ||||||
|         // make allocations in all of used size classes and free half of them
 |  | ||||||
| 
 |  | ||||||
|         const int max = 21000; |  | ||||||
|         void *ptrs[max]; |  | ||||||
| 
 |  | ||||||
|         for (int i = 0; i < max; ++i) { |  | ||||||
|             ptrs[i] = malloc(max); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         for (int i = 1; i < max; i += 2) { |  | ||||||
|             free(ptrs[i]); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     const size_t cnt = 3000; |     const size_t cnt = 3000; | ||||||
|     const size_t iter_cnt = 5; |     const size_t iter_cnt = 5; | ||||||
|     const size_t alloc_cnt = cnt * iter_cnt; |     const size_t alloc_cnt = cnt * iter_cnt; | ||||||
|  | @ -114,13 +99,9 @@ void tag_distinctness() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u8* alloc_default() { | u8* alloc_default() { | ||||||
|     if (rand() & 1) { |     u8 *p = (u8 *) malloc(DEFAULT_ALLOC_SIZE); | ||||||
|         int cnt = rand() & 0x3f; |     assert(p); | ||||||
|         for (int i = 0; i < cnt; ++i) { |     return p; | ||||||
|             (void) malloc(DEFAULT_ALLOC_SIZE); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return (u8 *) malloc(DEFAULT_ALLOC_SIZE); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| volatile u8 u8_var; | volatile u8 u8_var; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue