]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Merge branch 'master' into devel-3.0
[thirdparty/mdadm.git] / super1.c
index bf9e4c87fc6910ef6204b4698e736c345b325f85..35ef771a613c9b29db436737ae621a9ada692822 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -687,10 +687,8 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 
                if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
                    read(rfd, sb->device_uuid, 16) != 16) {
-                       *(__u32*)(sb->device_uuid) = random();
-                       *(__u32*)(sb->device_uuid+4) = random();
-                       *(__u32*)(sb->device_uuid+8) = random();
-                       *(__u32*)(sb->device_uuid+12) = random();
+                       __u32 r[4] = {random(), random(), random(), random()};
+                       memcpy(sb->device_uuid, r, 16);
                }
 
                sb->dev_roles[i] =
@@ -816,10 +814,8 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
        else {
                if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
                    read(rfd, sb->set_uuid, 16) != 16) {
-                       *(__u32*)(sb->set_uuid) = random();
-                       *(__u32*)(sb->set_uuid+4) = random();
-                       *(__u32*)(sb->set_uuid+8) = random();
-                       *(__u32*)(sb->set_uuid+12) = random();
+                       __u32 r[4] = {random(), random(), random(), random()};
+                       memcpy(sb->set_uuid, r, 16);
                }
                if (rfd >= 0) close(rfd);
        }
@@ -1023,12 +1019,12 @@ static int write_init_super1(struct supertype *st)
 
                if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
                    read(rfd, sb->device_uuid, 16) != 16) {
-                       *(__u32*)(sb->device_uuid) = random();
-                       *(__u32*)(sb->device_uuid+4) = random();
-                       *(__u32*)(sb->device_uuid+8) = random();
-                       *(__u32*)(sb->device_uuid+12) = random();
+                       __u32 r[4] = {random(), random(), random(), random()};
+                       memcpy(sb->device_uuid, r, 16);
                }
-               if (rfd >= 0) close(rfd);
+               if (rfd >= 0)
+                       close(rfd);
+
                sb->events = 0;
 
                refst =*st;