]> git.ipfire.org Git - thirdparty/man-pages.git/commit
netlink.7: Fix alignment issue in example
authorAntonin Décimo <antonin.decimo@gmail.com>
Fri, 27 Dec 2019 21:15:42 +0000 (22:15 +0100)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Mon, 30 Dec 2019 18:49:08 +0000 (19:49 +0100)
commitae10667d4891a592388f8dc63e1b01fed6a1b4bf
treebcd4ec2842dafb38016064b7244a579b59526de9
parent7aec4106be49a7ab35ef102f6473747cdd528c6a
netlink.7: Fix alignment issue in example

PVS-Studio reports that in

    char buf[8192];
    /* ... */
    nh = (struct nlmsghdr *) buf,

the pointer 'buf' is cast to a more strictly aligned pointer type.
This is undefined behaviour. One possible solution to make sure
that buf is correctly aligned is to declare buf as an array of
struct nlmsghdr. Other solutions include allocating the array on
the heap, use an union, or stdalign features.  With this patch,
the buffer still contains 8192 bytes.

This was raised on Stack Overflow:
https://stackoverflow.com/questions/57745580/netlink-receive-buffer-alignment

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man7/netlink.7