2016-10-20 01:31:50 +00:00
|
|
|
//
|
|
|
|
// MemoryFuzzer.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 19/10/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-10-20 01:31:50 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "MemoryFuzzer.hpp"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2017-11-11 20:28:40 +00:00
|
|
|
void Memory::Fuzz(uint8_t *buffer, std::size_t size) {
|
2017-10-21 23:49:04 +00:00
|
|
|
unsigned int divider = (static_cast<unsigned int>(RAND_MAX) + 1) / 256;
|
2016-10-20 01:31:50 +00:00
|
|
|
unsigned int shift = 1, value = 1;
|
2017-03-26 18:34:47 +00:00
|
|
|
while(value < divider) {
|
2016-10-20 01:31:50 +00:00
|
|
|
value <<= 1;
|
|
|
|
shift++;
|
|
|
|
}
|
|
|
|
|
2017-11-11 20:28:40 +00:00
|
|
|
for(std::size_t c = 0; c < size; c++) {
|
2017-10-04 02:04:15 +00:00
|
|
|
buffer[c] = static_cast<uint8_t>(std::rand() >> shift);
|
2016-10-20 01:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-05 14:36:07 +00:00
|
|
|
|
|
|
|
void Memory::Fuzz(std::vector<uint8_t> &buffer) {
|
|
|
|
Fuzz(buffer.data(), buffer.size());
|
|
|
|
}
|