netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Clang warnings in net/phonet
@ 2019-01-08  2:54 Nathan Chancellor
  2019-01-26  8:10 ` Nathan Chancellor
  2019-02-19 21:50 ` Arnd Bergmann
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-01-08  2:54 UTC (permalink / raw)
  To: Remi Denis-Courmont, David S. Miller
  Cc: netdev, linux-kernel, Nick Desaulniers

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];
                ^
net/phonet/pep.c:281:10: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
        switch (hdr->data[1]) {
                ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:285:12: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
                        switch (hdr->data[4]) {
                                ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:295:8: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
                        if (hdr->data[4] == PEP_IND_READY)
                            ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:304:21: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
                atomic_add(wake = hdr->data[4], &pn->tx_credits);
                                  ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:509:9: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
        n_sb = hdr->data[4];
               ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:817:14: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
        peer_type = hdr->other_pep_type << 8;
                    ^    ~~~~~~~~~~~~~~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
net/phonet/pep.c:820:9: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
        n_sb = hdr->data[4];
               ^         ~
include/net/phonet/pep.h:66:3: note: array 'data' declared here
                u8              data[1];
                ^
8 warnings generated.

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 :)

Thanks,
Nathan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Clang warnings in net/phonet
  2019-01-08  2:54 Clang warnings in net/phonet Nathan Chancellor
@ 2019-01-26  8:10 ` Nathan Chancellor
  2019-02-19 21:50 ` Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-01-26  8:10 UTC (permalink / raw)
  To: Rémi Denis-Courmont, Remi Denis-Courmont
  Cc: David S. Miller, netdev, linux-kernel, Nick Desaulniers

On Mon, Jan 07, 2019 at 07:54:20PM -0700, Nathan Chancellor 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];
>                 ^
> net/phonet/pep.c:281:10: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
>         switch (hdr->data[1]) {
>                 ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:285:12: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
>                         switch (hdr->data[4]) {
>                                 ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:295:8: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
>                         if (hdr->data[4] == PEP_IND_READY)
>                             ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:304:21: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
>                 atomic_add(wake = hdr->data[4], &pn->tx_credits);
>                                   ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:509:9: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
>         n_sb = hdr->data[4];
>                ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:817:14: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
>         peer_type = hdr->other_pep_type << 8;
>                     ^    ~~~~~~~~~~~~~~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> net/phonet/pep.c:820:9: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
>         n_sb = hdr->data[4];
>                ^         ~
> include/net/phonet/pep.h:66:3: note: array 'data' declared here
>                 u8              data[1];
>                 ^
> 8 warnings generated.
> 
> 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 :)
> 
> Thanks,
> Nathan

Gentle ping?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Clang warnings in net/phonet
  2019-01-08  2:54 Clang warnings in net/phonet Nathan Chancellor
  2019-01-26  8:10 ` Nathan Chancellor
@ 2019-02-19 21:50 ` Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-02-19 21:50 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Remi Denis-Courmont, David S. Miller, Networking,
	Linux Kernel Mailing List, Nick Desaulniers

On Tue, Jan 8, 2019 at 3:55 AM Nathan Chancellor
<natechancellor@gmail.com> 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
patch.

     Arnd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-19 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-08  2:54 Clang warnings in net/phonet Nathan Chancellor
2019-01-26  8:10 ` Nathan Chancellor
2019-02-19 21:50 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).