blob: c41aaec1a8309b9beffc58dd37601ef89ae7c7d3 (
plain)
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
|
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
FUZZ_STATIC uint32_t FUZZ_produceUint32Range(uint8_t *data, size_t size,
uint32_t min, uint32_t max) {
if (min > max) {
return 0;
}
uint32_t range = max - min;
uint32_t rolling = range;
uint32_t result = 0;
while (rolling > 0 && size > 0) {
uint8_t next = *(data + size - 1);
size -= 1;
result = (result << 8) | next;
}
if (range == 0xffffffff) {
return result;
}
return min + result % (range + 1);
}
|