1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

Update fuzzer sources

This commit is contained in:
Nick Terrell
2017-09-12 20:20:27 -07:00
parent f1571dad8f
commit 677c2cbf89
6 changed files with 43 additions and 18 deletions

View File

@ -19,6 +19,10 @@
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@ -48,11 +52,13 @@
/**
* Determininistically constructs a seed based on the fuzz input.
* Only looks at the first FUZZ_RNG_SEED_SIZE bytes of the input.
* Consumes up to the first FUZZ_RNG_SEED_SIZE bytes of the input.
*/
FUZZ_STATIC uint32_t FUZZ_seed(const uint8_t *src, size_t size) {
size_t const toHash = MIN(FUZZ_RNG_SEED_SIZE, size);
return XXH32(src, toHash, 0);
FUZZ_STATIC uint32_t FUZZ_seed(uint8_t const **src, size_t* size) {
size_t const toHash = MIN(FUZZ_RNG_SEED_SIZE, *size);
return XXH32(*src, toHash, 0);
*size -= toHash;
*src += toHash;
}
#define FUZZ_rotl32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
@ -67,4 +73,8 @@ FUZZ_STATIC uint32_t FUZZ_rand(uint32_t *state) {
return rand32 >> 5;
}
#ifdef __cplusplus
}
#endif
#endif