]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/c.h: handle members of const struct
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 12 Jan 2024 06:51:39 +0000 (07:51 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 12 Jan 2024 06:54:13 +0000 (07:54 +0100)
Trying to copy into a local const struct will lead to a compiler error.
By adding a "+ 0" to the argument of __typeof__() the type of the
resulting express will loose its constness.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
include/c.h

index 36eb2a9e7f80045588164f4cc4ef3f8a90f72321..e353643fdd88998f3332165663e7ed03b3e26268 100644 (file)
 
 #define read_unaligned_member(p, m) __extension__ ({          \
        size_t offset = offsetof(__typeof__(* p), m);         \
-       __typeof__(p->m) v;                                   \
+       __typeof__(p->m + 0) v;                               \
        memcpy(&v, ((unsigned char *)p) + offset, sizeof(v)); \
        v; })