https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

--- Comment #6 from Arnd Bergmann <arnd at linaro dot org> ---
I figured out the qnx4 warning in the end: https://godbolt.org/z/hvqjr3

struct qnx4_inode_entry {
    char di_status;
    union {
        struct {
            char di_fname[16];
            char di_pad[32];
        };

        struct {
            char dl_fname[48];
        };
    };
};

int qnx4_readdir(struct qnx4_inode_entry *de)
{
    if (!de->di_fname[0])
        return 0;
    if (de->di_status)
        return __builtin_strnlen(de->di_fname, sizeof(de->di_fname));
    else
        return __builtin_strnlen(de->dl_fname, sizeof(de->dl_fname));
    return 0;
}

This produces

<source>:22:16: warning: '__builtin_strnlen' specified bound 48 exceeds source
size 16 [-Wstringop-overread]

because the first access on the object seems to decide which layout is assumed.
Changing (!de->di_fname[0]) to (!de->dl_fname[0]) shuts up the warning since
that is a longer field. This is probably enough as a workaround, if you can
confirm that the behavior of the compiler is also intentional for this input.

Reply via email to