1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-15 15:06:42 +00:00

Dont cast from char* to struct chrp_header* which has a bigger alignment

requirements. Copy it via union instead. Fixes a clang warning about
alignment.

Reviewed by:    sobomax
This commit is contained in:
Roman Divacky 2012-08-27 14:51:26 +00:00
parent ae7f84a9a4
commit b1fcaf5f95
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=239733

View File

@ -51,12 +51,16 @@ struct deletelist {
struct deletelist *last; struct deletelist *last;
}; };
union {
uint8_t buf[sizeof(struct chrp_header)];
struct chrp_header header;
} conv;
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int opt, dump, fd, res, i, size; int opt, dump, fd, res, i, size;
uint8_t buf[NVRAM_SIZE], *cp, *common; uint8_t buf[NVRAM_SIZE], *cp, *common;
struct chrp_header *header;
struct deletelist *dl; struct deletelist *dl;
dump = 0; dump = 0;
@ -116,9 +120,9 @@ main(int argc, char **argv)
/* Locate common block */ /* Locate common block */
size = 0; size = 0;
for (cp = buf; cp < buf + sizeof(buf); cp += size) { for (cp = buf; cp < buf + sizeof(buf); cp += size) {
header = (struct chrp_header *)cp; memcpy(conv.buf, cp, sizeof(struct chrp_header));
size = header->length * 0x10; size = conv.header.length * 0x10;
if (strncmp(header->name, "common", 7) == 0) if (strncmp(conv.header.name, "common", 7) == 0)
break; break;
} }
if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header)) if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header))