1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <stdlib.h>
#include "arch.h" // page_size
#include "sanitise.h"
#include "random.h"
unsigned long get_len(void)
{
int i = 0;
i = rand32();
/* short circuit if 0 */
if (i == 0)
return 0;
switch (rand() % 6) {
case 0: i &= 0xff;
break;
case 1: i &= page_size;
break;
case 2: i &= 0xffff;
break;
case 3: i &= 0xffffff;
break;
case 4: i &= 0xffffffff;
break;
default:
// Pass through
break;
}
/* again, short circuit if 0 */
if (i == 0)
return 0;
/* we might get lucky if something is counting ints/longs etc. */
if (rand() % 100 < 25) {
int _div = 1 << ((rand() % 4) + 1); /* 2,4,8 or 16 */
i /= _div;
}
return i;
}
|