Re: Clang warnings in net/phonet

From: Arnd Bergmann
Date: Tue Feb 19 2019 - 16:50:59 EST

On Tue, Jan 8, 2019 at 3:55 AM Nathan Chancellor
<natechancellor@xxxxxxxxx> wrote:
> Hi all,
> When building the kernel with Clang, this warning comes up in net/phonet.
> net/phonet/pep.c:224:16: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
> ph->data[0] = oph->data[1]; /* CTRL id */
> ^ ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
> u8 data[1];
> ^
> I have taken a look at the effected code but I can't really figure out
> the proper fix for this warning (my knowledge of C just isn't there
> yet). Nick had suggested changing 'u8 data[1]' to 'u8 *data' in
> 'struct pnpipehdr', which seems logical but I can't say for sure. Any
> advice would be appreciated :)

A pointer wouldn't work here, as this is a network header with a
fixed layout. Using a flexible array at the end of the structure works,
but unfortunately all indices change that way. Sending an experimental