Make RAND_RANGE() a macro
PATCH 12/12 Make RAND_RANGE() a macro
From: Tyson Smith <[email protected]>
Renamed to uppercase to match other macros. Removed swap call. This should be done outside of the call.
--- fd-sockets.c | 2 +- fds.c | 5 ++++- generate-args.c | 2 +- include/random.h | 2 +- net/proto-udp.c | 2 +- net/proto-udplite.c | 2 +- random-address.c | 2 +- random-length.c | 2 +- random.c | 12 ++---------- 9 files changed, 13 insertions(+), 18 deletions(-)
fd-sockets.c +1 -1
@@ -88,7 +88,7 @@ static int open_socket(unsigned int domain, unsigned int type, unsigned int prot ret =bind (fd, sa, salen);if (ret !=-1 ) { - (void )listen (fd,rand_range (1 ,128 )); + (void )listen (fd,RAND_RANGE (1 ,128 )); } }
fds.c +4 -1
@@ -125,7 +125,10 @@ int get_random_fd(void) regen:if (shm->fd_lifetime ==0 ) { shm->current_fd =get_new_random_fd (); - shm->fd_lifetime =rand_range (5 , max_children); +if (max_children >5 ) + shm->fd_lifetime =RAND_RANGE (5 , max_children); +else + shm->fd_lifetime =RAND_RANGE (max_children,5 ); }else shm->fd_lifetime--;
generate-args.c +1 -1
@@ -162,7 +162,7 @@ static unsigned long handle_arg_iovec(struct syscallentry *entry, struct syscall {unsigned long num_entries; - num_entries =rand_range (1 ,256 ); + num_entries =RAND_RANGE (1 ,256 );switch (argnum) {case 1 :if (entry->arg2type ==ARG_IOVECLEN )
include/random.h +1 -1
@@ -15,6 +15,7 @@#define RAND_BOOL () (rand() & 1)#define RAND_BYTE () (rand() & 0xff) +#define RAND_RANGE (min, max) (min + rand() / (RAND_MAX / (max - min + 1) + 1))extern unsigned int seed;unsigned int init_seed (unsigned int seed);
@@ -25,6 +26,5 @@ unsigned int new_seed(void);void generate_rand_bytes (unsigned char *ptr,unsigned int len);unsigned int rand32 (void );u64 rand64 (void ); -unsigned int rand_range (unsigned int min,unsigned int max);unsigned long rand_single_bit (unsigned char size);unsigned long set_rand_bitmask (unsigned int num,const unsigned long *values);
net/proto-udp.c +1 -1
@@ -23,7 +23,7 @@ void udp_setsockopt(struct sockopt *so)break ;case UDP_ENCAP : optval = (char *) so->optval; - optval[0 ] =rand_range (1 ,3 );// Encapsulation types. + optval[0 ] =RAND_RANGE (1 ,3 );// Encapsulation types. break ;default :break ;
net/proto-udplite.c +1 -1
@@ -25,7 +25,7 @@ void udplite_setsockopt(struct sockopt *so)break ;case UDP_ENCAP : optval = (char *) so->optval; - optval[0 ] =rand_range (1 ,3 );// Encapsulation types. + optval[0 ] =RAND_RANGE (1 ,3 );// Encapsulation types. break ;case UDPLITE_SEND_CSCOV :break ;
random-address.c +1 -1
@@ -40,7 +40,7 @@ static void * _get_address(unsigned char null_allowed)if (null_allowed == TRUE) i =rand () %4 ;else - i =rand_range (1 ,3 ); + i =RAND_RANGE (1 ,3 );switch (i) {case 0 : addr =NULL ;
random-length.c +1 -1
@@ -37,7 +37,7 @@ unsigned long get_len(void)/* we might get lucky if something is counting ints/longs etc. */ if (ONE_IN (4 )) { -int _div =1 <<rand_range (1 ,4 );/* 2,4,8 or 16 */ +int _div =1 <<RAND_RANGE (1 ,4 );/* 2,4,8 or 16 */ i /= _div; }
random.c +2 -10
@@ -36,14 +36,6 @@ void generate_rand_bytes(unsigned char *ptr, unsigned int len) } } -unsigned int rand_range (unsigned int min,unsigned int max) -{ -if (min > max) -swap (min, max); - -return min +rand () / (RAND_MAX / (max - min +1 ) +1 ); -} -/* * OR a random number of bits into a mask. * Used by ARG_LIST generation, and get_o_flags()
@@ -54,7 +46,7 @@ unsigned long set_rand_bitmask(unsigned int num, const unsigned long *values)unsigned long mask =0 ;unsigned int bits; - bits =rand_range (0 , num);/* num of bits to OR */ + bits =RAND_RANGE (0 , num);/* num of bits to OR */ if (bits ==0 )return mask;
@@ -134,7 +126,7 @@ unsigned int rand32(void)/* we might get lucky if something is counting ints/longs etc. */ if (ONE_IN (4 )) { -int _div =1 <<rand_range (1 ,4 );/* 2,4,8 or 16 */ +int _div =1 <<RAND_RANGE (1 ,4 );/* 2,4,8 or 16 */ r /= _div; }
Signature · 1 line
1.9.1