aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-03-16 14:08:44 -0700
committerAndres Freund <andres@anarazel.de>2023-03-16 14:48:47 -0700
commitc1266562feebf167105a15b0575ad863492d533d (patch)
treeadb6dcc8684c2fab71c16a64234afc5451a55c24 /src
parent6f508b8bce2ed66eef310e1b77a84ce1cd222aeb (diff)
downloadpostgresql-c1266562feebf167105a15b0575ad863492d533d.tar.gz
postgresql-c1266562feebf167105a15b0575ad863492d533d.zip
Work around spurious compiler warning in inet operators
gcc 12+ has complaints like the following: ../../../../../pgsql/src/backend/utils/adt/network.c: In function 'inetnot': ../../../../../pgsql/src/backend/utils/adt/network.c:1893:34: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 1893 | pdst[nb] = ~pip[nb]; | ~~~~~~~~~^~~~~~~~~~ ../../../../../pgsql/src/include/utils/inet.h:27:23: note: at offset -1 into destination object 'ipaddr' of size 16 27 | unsigned char ipaddr[16]; /* up to 128 bits of address */ | ^~~~~~ ../../../../../pgsql/src/include/utils/inet.h:27:23: note: at offset -1 into destination object 'ipaddr' of size 16 This is due to a compiler bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104986 It has been a year since the bug has been reported without getting fixed. As the warnings are verbose and use of gcc 12 is becoming more common, it seems worth working around the bug. Particularly because a simple reformulation of the loop condition fixes the issue and isn't any less readable. Author: Tom Lane <tgl@sss.pgh.pa.us> Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/144536.1648326206@sss.pgh.pa.us Backpatch: 11-
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/network.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 5e980cf23f0..607a077c1cc 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1490,7 +1490,7 @@ inetnot(PG_FUNCTION_ARGS)
unsigned char *pip = ip_addr(ip);
unsigned char *pdst = ip_addr(dst);
- while (nb-- > 0)
+ while (--nb >= 0)
pdst[nb] = ~pip[nb];
}
ip_bits(dst) = ip_bits(ip);
@@ -1522,7 +1522,7 @@ inetand(PG_FUNCTION_ARGS)
unsigned char *pip2 = ip_addr(ip2);
unsigned char *pdst = ip_addr(dst);
- while (nb-- > 0)
+ while (--nb >= 0)
pdst[nb] = pip[nb] & pip2[nb];
}
ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2));
@@ -1554,7 +1554,7 @@ inetor(PG_FUNCTION_ARGS)
unsigned char *pip2 = ip_addr(ip2);
unsigned char *pdst = ip_addr(dst);
- while (nb-- > 0)
+ while (--nb >= 0)
pdst[nb] = pip[nb] | pip2[nb];
}
ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2));
@@ -1579,7 +1579,7 @@ internal_inetpl(inet *ip, int64 addend)
unsigned char *pdst = ip_addr(dst);
int carry = 0;
- while (nb-- > 0)
+ while (--nb >= 0)
{
carry = pip[nb] + (int) (addend & 0xFF) + carry;
pdst[nb] = (unsigned char) (carry & 0xFF);
@@ -1663,7 +1663,7 @@ inetmi(PG_FUNCTION_ARGS)
unsigned char *pip2 = ip_addr(ip2);
int carry = 1;
- while (nb-- > 0)
+ while (--nb >= 0)
{
int lobyte;