generator: tweak generate_random_data logic
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2021-12-11 21:33:42 +01:00
parent fb02ef9a23
commit d907c9db6e
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -186,13 +186,18 @@ auto Generator::generate_blocks(unsigned int k_blocks) -> std::string {
auto Generator::generate_random_data(uint n) -> std::string {
// fmt::print("n -> {}\n", n); // debugging
if (n < 0){
/* this should not be possible */
fmt::print("[*] error: n cannot be < 0\n");
throw std::invalid_argument("n cannot be < 0");
} else if (n > pow(2,20)){
fmt::print("[*] error: n cannot be > 2^20\n");
throw std::invalid_argument("n cannot be > 2^20");
if (n == 0) {
// do not do this..?
const std::string msg{"zero bytes requested, bailing\n"};
fmt::print("[*] error: {}", msg);
throw std::invalid_argument(msg);
}
// pre-computed 2^20
if (n > 1048576) {
const std::string msg{"n cannot be > 2^20\n"};
fmt::print("[*] error: {}", msg);
throw std::invalid_argument(msg);
}
std::string r;