* Fix ratio so that it talks about bits, not bytes.

This commit is contained in:
Sam Hocevar 2006-12-15 17:47:59 +00:00 committed by sam
parent 8c26a7f04c
commit 4c8da1b060
2 changed files with 6 additions and 6 deletions

View File

@ -38,7 +38,7 @@
* associated seed that can be computed from the zzuf seed, the chunk * associated seed that can be computed from the zzuf seed, the chunk
* index and the fuzziness density. This allows us to predictably fuzz * index and the fuzziness density. This allows us to predictably fuzz
* any part of the file without reading the whole file. */ * any part of the file without reading the whole file. */
#define CHUNKSIZE 1024 #define CHUNKBYTES 1024
void zzuf_fuzz(int fd, uint8_t *buf, uint64_t len) void zzuf_fuzz(int fd, uint8_t *buf, uint64_t len)
{ {
@ -48,19 +48,19 @@ void zzuf_fuzz(int fd, uint8_t *buf, uint64_t len)
start = files[fd].pos; start = files[fd].pos;
stop = start + len; stop = start + len;
for(i = start / CHUNKSIZE; i < (stop + CHUNKSIZE - 1) / CHUNKSIZE; i++) for(i = start / CHUNKBYTES; i < (stop + CHUNKBYTES - 1) / CHUNKBYTES; i++)
{ {
uint32_t chunkseed = i * MAGIC1; uint32_t chunkseed = i * MAGIC1;
/* Add some random dithering to handle ratio < 1.0/CHUNKSIZE */ /* Add some random dithering to handle ratio < 1.0/CHUNKBYTES */
zzuf_srand(_zzuf_seed ^ chunkseed); zzuf_srand(_zzuf_seed ^ chunkseed);
todo = (int)((_zzuf_ratio * (CHUNKSIZE * 1000) + zzuf_rand(1000)) todo = (int)((_zzuf_ratio * (8 * CHUNKBYTES * 1000) + zzuf_rand(1000))
/ 1000.0); / 1000.0);
zzuf_srand(_zzuf_seed ^ chunkseed ^ (todo * MAGIC2)); zzuf_srand(_zzuf_seed ^ chunkseed ^ (todo * MAGIC2));
while(todo--) while(todo--)
{ {
uint64_t idx = i * CHUNKSIZE + zzuf_rand(CHUNKSIZE); uint64_t idx = i * CHUNKBYTES + zzuf_rand(CHUNKBYTES);
uint8_t byte = (1 << zzuf_rand(8)); uint8_t byte = (1 << zzuf_rand(8));
if(idx < start || idx >= stop) if(idx < start || idx >= stop)

View File

@ -41,7 +41,7 @@
int _zzuf_ready = 0; int _zzuf_ready = 0;
int _zzuf_debug = 0; int _zzuf_debug = 0;
int _zzuf_seed = 0; int _zzuf_seed = 0;
float _zzuf_ratio = 0.057f; float _zzuf_ratio = 0.004f;
regex_t * _zzuf_include = NULL; regex_t * _zzuf_include = NULL;
regex_t * _zzuf_exclude = NULL; regex_t * _zzuf_exclude = NULL;