On Tue, 31 Mar 2020 15:08:26 +0100
Kevin Traynor <ktray...@redhat.com> wrote:

> struct virtchnl_rss_key {
>         u16 vsi_id;
>         u16 key_len;
>         u8 key[1];         /* RSS hash key, packed bytes */
>         ^^^^^^^^^
> };
> 
> Then in iavf_configure_rss_key()
> 
>       len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
>                                              ^^^^^^^^^^^^
>       rss_key = rte_zmalloc("rss_key", len, 0);
>                   ^^^ extra space beyond key[1] allocated here
> 
> <snip>
>       rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
>                           ^^^                           ^^^^^^^^^^^^
> 
> At runtime we have allocated extra space at the end of the struct for
> key, and the same size used in the malloc is also considered when
> finding the right branches in the memcpy fns. But the compiler does not
> know value of size and it simply sees there can be casts of a 1 byte key
> to 16 or 32 bytes in some branches of the memcpy fns, so gives a warning.

The standard way to do such a thing is to use an empty
array. The Linux kernel has just gone through cleaning up
all these zero length (and it this case one) array at
end of function.

Reply via email to