X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Frand.c;fp=lib%2Frand.c;h=995035fea742ad211f757bc12427c2160629b4c1;hp=66d04729a49eaa073f822d77a93b66ae426f659d;hb=811ac503a6196f13da22565eb165c278988da4da;hpb=9c42684e32325da26e862280388798343c5f1305 diff --git a/lib/rand.c b/lib/rand.c index 66d04729..995035fe 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -34,7 +34,6 @@ */ #include -#include #include "rand.h" #include "../hash.h" @@ -95,10 +94,16 @@ unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf, unsigned int percentage, unsigned int segment, unsigned int len) { - unsigned int this_len, rep_len; unsigned long r = __rand(fs); + unsigned int this_len; - assert(segment <= len); + if (percentage == 100) { + memset(buf, 0, len); + return 0; + } + + if (segment > len) + segment = len; if (sizeof(int) != sizeof(long *)) r *= (unsigned long) __rand(fs); @@ -116,16 +121,10 @@ unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf, len -= this_len; buf += this_len; - /* - * Now duplicate random chunk in rest of buf - */ - rep_len = segment - this_len; - if (rep_len > len) - rep_len = len; + if (this_len > len) + this_len = len; - memcpy(buf, buf + rep_len, rep_len); - buf += rep_len; - len -= rep_len; + memset(buf, 0, this_len); } return r;