[systemd-devel] [PATCH] util: fix strict aliasing violations in use of struct inotify_event

Uoti Urpala uoti.urpala at pp1.inet.fi
Mon Dec 22 08:47:32 PST 2014

On Mon, 2014-12-22 at 00:17 -0800, Shawn Paul Landden wrote:
> There is alot of cleanup that will have to happen to turn on
> -fstrict-aliasing, but I think our code should be "correct" to the rule.

> -                uint8_t buffer[INOTIFY_EVENT_MAX] _alignas_(struct inotify_event);
> +                union {
> +                        struct inotify_event ev;
> +                        uint8_t raw[INOTIFY_EVENT_MAX];
> +                } buffer;

I don't think the union is really necessary for correctness here. Access
through a character type may legally alias access by any other type.
Strictly speaking, "character types" are "char", "signed char" and
"unsigned char", and is not required to include uint8_t, but I don't
think this is an issue in practice. Thus the existing code should be
strict-aliasing safe unless I'm missing something.

More information about the systemd-devel mailing list