]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix gcc-4.4 compiler warning.
authorNeilBrown <neilb@suse.de>
Wed, 29 Apr 2009 01:44:02 +0000 (11:44 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 29 Apr 2009 01:44:02 +0000 (11:44 +1000)
Apparently the dereferencing of a type-punned pointer breaks strict
aliasing rules.   And we wouldn't want to do that.
So just make a different array of the appropriate type and use memcpy.

Resolves-Debian-bug: 505375
Signed-off-by: NeilBrown <neilb@suse.de>
bitmap.c
super1.c

index 352be5d7261a7e130ad900bbbf3d2ff1b5128c34..5618087719cfa199de5e6078eb9f348ac1a313fc 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -270,6 +270,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
        int rv = 1;
        char buf[64];
        int swap;
+       __u32 uuid32[4];
 
        info = bitmap_file_read(filename, brief, &st);
        if (!info)
@@ -297,19 +298,20 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
 #else
                swap = 1;
 #endif
-       if (swap) {
-       printf("            UUID : %08x:%08x:%08x:%08x\n",
-                                       swapl(*(__u32 *)(sb->uuid+0)),
-                                       swapl(*(__u32 *)(sb->uuid+4)),
-                                       swapl(*(__u32 *)(sb->uuid+8)),
-                                       swapl(*(__u32 *)(sb->uuid+12)));
-       } else {
-       printf("            UUID : %08x:%08x:%08x:%08x\n",
-                                       *(__u32 *)(sb->uuid+0),
-                                       *(__u32 *)(sb->uuid+4),
-                                       *(__u32 *)(sb->uuid+8),
-                                       *(__u32 *)(sb->uuid+12));
-       }
+       memcpy(uuid32, sb->uuid, 16);
+       if (swap)
+               printf("            UUID : %08x:%08x:%08x:%08x\n",
+                      swapl(uuid32[0]),
+                      swapl(uuid32[1]),
+                      swapl(uuid32[2]),
+                      swapl(uuid32[3]));
+       else
+               printf("            UUID : %08x:%08x:%08x:%08x\n",
+                      uuid32[0],
+                      uuid32[1],
+                      uuid32[2],
+                      uuid32[3]);
+
        printf("          Events : %llu\n", (unsigned long long)sb->events);
        printf("  Events Cleared : %llu\n", (unsigned long long)sb->events_cleared);
        printf("           State : %s\n", bitmap_state(sb->state));
index 134241249736f552412f7d943c51ee68682d22b3..037c5eb2f575bc8d90c1f0dd7182377a075bebdd 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -612,10 +612,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] =
@@ -735,10 +733,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);
        }
@@ -912,11 +908,10 @@ 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);
        sb->events = 0;