Fix gcc-4.4 compiler warning.

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>
This commit is contained in:
NeilBrown 2009-04-29 11:44:02 +10:00
parent 667e66d329
commit caa0f6c623
2 changed files with 22 additions and 25 deletions

View File

@ -270,6 +270,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
int rv = 1; int rv = 1;
char buf[64]; char buf[64];
int swap; int swap;
__u32 uuid32[4];
info = bitmap_file_read(filename, brief, &st); info = bitmap_file_read(filename, brief, &st);
if (!info) if (!info)
@ -297,19 +298,20 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
#else #else
swap = 1; swap = 1;
#endif #endif
if (swap) { memcpy(uuid32, sb->uuid, 16);
printf(" UUID : %08x:%08x:%08x:%08x\n", if (swap)
swapl(*(__u32 *)(sb->uuid+0)), printf(" UUID : %08x:%08x:%08x:%08x\n",
swapl(*(__u32 *)(sb->uuid+4)), swapl(uuid32[0]),
swapl(*(__u32 *)(sb->uuid+8)), swapl(uuid32[1]),
swapl(*(__u32 *)(sb->uuid+12))); swapl(uuid32[2]),
} else { swapl(uuid32[3]));
printf(" UUID : %08x:%08x:%08x:%08x\n", else
*(__u32 *)(sb->uuid+0), printf(" UUID : %08x:%08x:%08x:%08x\n",
*(__u32 *)(sb->uuid+4), uuid32[0],
*(__u32 *)(sb->uuid+8), uuid32[1],
*(__u32 *)(sb->uuid+12)); uuid32[2],
} uuid32[3]);
printf(" Events : %llu\n", (unsigned long long)sb->events); printf(" Events : %llu\n", (unsigned long long)sb->events);
printf(" Events Cleared : %llu\n", (unsigned long long)sb->events_cleared); printf(" Events Cleared : %llu\n", (unsigned long long)sb->events_cleared);
printf(" State : %s\n", bitmap_state(sb->state)); printf(" State : %s\n", bitmap_state(sb->state));

View File

@ -612,10 +612,8 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
read(rfd, sb->device_uuid, 16) != 16) { read(rfd, sb->device_uuid, 16) != 16) {
*(__u32*)(sb->device_uuid) = random(); __u32 r[4] = {random(), random(), random(), random()};
*(__u32*)(sb->device_uuid+4) = random(); memcpy(sb->device_uuid, r, 16);
*(__u32*)(sb->device_uuid+8) = random();
*(__u32*)(sb->device_uuid+12) = random();
} }
sb->dev_roles[i] = sb->dev_roles[i] =
@ -735,10 +733,8 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
else { else {
if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
read(rfd, sb->set_uuid, 16) != 16) { read(rfd, sb->set_uuid, 16) != 16) {
*(__u32*)(sb->set_uuid) = random(); __u32 r[4] = {random(), random(), random(), random()};
*(__u32*)(sb->set_uuid+4) = random(); memcpy(sb->set_uuid, r, 16);
*(__u32*)(sb->set_uuid+8) = random();
*(__u32*)(sb->set_uuid+12) = random();
} }
if (rfd >= 0) close(rfd); 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 || if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
read(rfd, sb->device_uuid, 16) != 16) { read(rfd, sb->device_uuid, 16) != 16) {
*(__u32*)(sb->device_uuid) = random(); __u32 r[4] = {random(), random(), random(), random()};
*(__u32*)(sb->device_uuid+4) = random(); memcpy(sb->device_uuid, r, 16);
*(__u32*)(sb->device_uuid+8) = random();
*(__u32*)(sb->device_uuid+12) = random();
} }
if (rfd >= 0) close(rfd); if (rfd >= 0) close(rfd);
sb->events = 0; sb->events = 0;