]> git.ipfire.org Git - thirdparty/tvheadend.git/commit
Simplify IPv6 compare functions to unconfuse gcc compiler
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 3 Nov 2022 22:53:30 +0000 (23:53 +0100)
committerFlole998 <Flole998@users.noreply.github.com>
Mon, 21 Nov 2022 01:33:44 +0000 (02:33 +0100)
commitc0f616e56bc4df70978a060b72f8c6a7ca487d3f
tree485d55f24567c5633e8aa92771ae8810df2cf577
parentfed1eeb4d120ac2b0f3728bd63280c27ad94834d
Simplify IPv6 compare functions to unconfuse gcc compiler

In file included from src/tcp.c:32:
In function ‘ip_check_is_any_v6’,
    inlined from ‘ip_check_is_any’ at src/tcp.h:110:46,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:89:17:
src/tcp.h:105:57: warning: array subscript 1 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Warray-bounds]
  105 |   { return ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[0] == ((uint64_t *)(&in6addr_any.s6_addr))[0] &&
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:108:19: note: at offset 8 into object ‘address’ of size 8
  108 | static inline int ip_check_is_any(const struct sockaddr_storage *address)
      |                   ^~~~~~~~~~~~~~~

And more for the other half of the function and its three-times more or
less copy-paste instances. sockaddr_storage is not an array, but what
we actually do here is access s6_addr – which is an array of uint8_t.
Accessing the 16 uint8_t as 2 uint64_t apparently works, but not doing
it results in hopefully simpler to understand code for both humans and
compilers alike.
src/tcp.h