On Wed, May 17, 2023 at 05:32:50PM -0500, Eric Blake wrote:
On Wed, May 17, 2023 at 11:06:59AM +0100, Richard W.M. Jones wrote:
+static void +corrupt_all_bits (uint8_t *buf, uint32_t count, + struct random_state *rs, enum corruption_type ct) +{ + size_t i; + unsigned bit; + uint64_t rand; + + /* This is used when MAXP < P <= 100%. We treat it the same as 100% + * and corrupt all bits. + */ + for (i = 0; i < count; ++i) { + for (bit = 0; bit < 8; ++bit) { + rand = xrandom (rs); + buf[i] = corrupt_one_bit (buf[i], bit, rand, ct); + } + }
Is this actually corrupting all bits, or corrupting 1 bit per byte? I found the function name a bit confusing. (Doing XOR with -1 to invert all bits is not the same as choosing a random bit pattern but where only about 50% of the bits get flipped - but both behaviors can prove interesting to see how filesystems cope with such corruptions)
Isn't it corrupting each bit in turn, in effect corrupting all of them? However we could use a local variable to store buf[i] during the inner loop. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW