]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: prefer memcpy() to manual pointer arithmetic
authorSami Kerola <kerolasa@iki.fi>
Sat, 27 Jul 2019 17:55:01 +0000 (18:55 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 27 Jul 2019 18:00:34 +0000 (19:00 +0100)
With pointer arithmetic clang address sanitizer gives following error this
change addresses.  Notice the following happens only when running as root.

sys-utils/lscpu-dmi.c:83:14: runtime error: load of misaligned address
0x55a1d62f3d1d for type 'const uint16_t' (aka 'const unsigned short'), which
requires 2 byte alignment

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/lscpu-dmi.c

index 29bd2e4fc92987d065e72fe9bd5d05237011fba5..82d8ed44308ff0b388bbb31baf5fc98c9f28a95e 100644 (file)
@@ -80,7 +80,7 @@ static void to_dmi_header(struct dmi_header *h, uint8_t *data)
 {
        h->type = data[0];
        h->length = data[1];
-       h->handle = WORD(data + 2);
+       memcpy(&h->handle, data + 2, sizeof(h->handle));
        h->data = data;
 }