diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2012-08-27 14:51:26 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2012-08-27 14:51:26 +0000 |
commit | 7685cb7599fe1207f6008b27f5074376ec9116e9 (patch) | |
tree | 1838d93cce9d3d29b1c1695f8816b75b0c85d8cd /usr.sbin/nvram/nvram.c | |
parent | 2d4d812fecc8adc9c98e129a432978ed92fe0841 (diff) | |
download | FreeBSD-src-7685cb7599fe1207f6008b27f5074376ec9116e9.zip FreeBSD-src-7685cb7599fe1207f6008b27f5074376ec9116e9.tar.gz |
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
Diffstat (limited to 'usr.sbin/nvram/nvram.c')
-rw-r--r-- | usr.sbin/nvram/nvram.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.sbin/nvram/nvram.c b/usr.sbin/nvram/nvram.c index 9d56f9d..a286ee3 100644 --- a/usr.sbin/nvram/nvram.c +++ b/usr.sbin/nvram/nvram.c @@ -51,12 +51,16 @@ struct deletelist { struct deletelist *last; }; +union { + uint8_t buf[sizeof(struct chrp_header)]; + struct chrp_header header; +} conv; + int main(int argc, char **argv) { int opt, dump, fd, res, i, size; uint8_t buf[NVRAM_SIZE], *cp, *common; - struct chrp_header *header; struct deletelist *dl; dump = 0; @@ -116,9 +120,9 @@ main(int argc, char **argv) /* Locate common block */ size = 0; for (cp = buf; cp < buf + sizeof(buf); cp += size) { - header = (struct chrp_header *)cp; - size = header->length * 0x10; - if (strncmp(header->name, "common", 7) == 0) + memcpy(conv.buf, cp, sizeof(struct chrp_header)); + size = conv.header.length * 0x10; + if (strncmp(conv.header.name, "common", 7) == 0) break; } if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header)) |