fix gcc maybe-uninitialized compiler warnings in match_sockaddr
authorLee <ler762@users.sourceforge.net>
Wed, 9 Aug 2023 08:34:55 +0000 (04:34 -0400)
committerLee <ler762@users.sourceforge.net>
Wed, 9 Aug 2023 08:34:55 +0000 (04:34 -0400)
I can't tell if they're false positives or not, but compiling with
no warnings is better than seeing this:

filters.c: In function ‘match_sockaddr’:
filters.c:205:42: warning: ‘address_port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  205 |    if (*netmask_port && *network_port != *address_port)
      |                                          ^~~~~~~~~~~~~
filters.c:214:24: warning: ‘address_addr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  214 |           (address_addr[i] & netmask_addr[i]))
      |            ~~~~~~~~~~~~^~~
filters.c:205:8: warning: ‘netmask_port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  205 |    if (*netmask_port && *network_port != *address_port)
      |        ^~~~~~~~~~~~~
filters.c:200:20: warning: ‘netmask_addr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  200 |       netmask_addr += 12;
      |                    ^~
filters.c:205:25: warning: ‘network_port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  205 |    if (*netmask_port && *network_port != *address_port)
      |                         ^~~~~~~~~~~~~
filters.c:172:17: warning: ‘addr_len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  172 |    unsigned int addr_len;
      |                 ^~~~~~~~

filters.c

index 35c8476..86a1dfc 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -173,6 +173,14 @@ static int match_sockaddr(const struct sockaddr_storage *network,
    in_port_t *network_port, *netmask_port, *address_port;
    int i;
 
    in_port_t *network_port, *netmask_port, *address_port;
    int i;
 
+   network_addr = NULL;
+   netmask_addr = NULL;
+   address_addr = NULL;
+   addr_len = 0;
+   network_port = NULL;
+   netmask_port = NULL;
+   address_port = NULL;
+
    if (network->ss_family != netmask->ss_family)
    {
       /* This should never happen */
    if (network->ss_family != netmask->ss_family)
    {
       /* This should never happen */