lib/rand: fix bug with non uint64_t aligned random buffer fill

Now that we honor the compression percentage, we can easily
get buffer fills that are not aligned to uint64_t. Make
sure that __fill_random_buf() handles this correctly.

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/lib/rand.c b/lib/rand.c
index 618a2f0..32aec20 100644
--- a/lib/rand.c
+++ b/lib/rand.c
@@ -69,11 +69,26 @@
 
 void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
 {
-	long *ptr = buf;
+	void *ptr = buf;
 
-	while ((void *) ptr - buf < len) {
-		*ptr = seed;
-		ptr++;
+	while (len) {
+		if (len >= sizeof(int64_t)) {
+			*((int64_t *) ptr) = seed;
+			ptr += sizeof(int64_t);
+			len -= sizeof(int64_t);
+		} else if (len >= sizeof(int32_t)) {
+			*((int32_t *) ptr) = seed;
+			ptr += sizeof(int32_t);
+			len -= sizeof(int32_t);
+		} else if (len >= sizeof(int16_t)) {
+			*((int16_t *) ptr) = seed;
+			ptr += sizeof(int16_t);
+			len -= sizeof(int16_t);
+		} else {
+			*((int8_t *) ptr) = seed;
+			ptr += sizeof(int8_t);
+			len -= sizeof(int8_t);
+		}
 		seed *= GOLDEN_RATIO_PRIME;
 		seed >>= 3;
 	}
@@ -146,10 +161,14 @@
 		__fill_random_buf(buf, this_len, seed);
 
 		len -= this_len;
+		if (!len)
+			break;
 		buf += this_len;
 
 		if (this_len > len)
 			this_len = len;
+		else if (len - this_len <= sizeof(long))
+			this_len = len;
 
 		if (pbytes)
 			fill_pattern(buf, this_len, pattern, pbytes);