Commit 5858cf8a authored by Tom Lane's avatar Tom Lane

Fix header comment for bitncmp().

The result is an int less than, equal to, or greater than zero, in the
style of memcmp (and, in fact, exactly the output of memcmp in some cases).
This comment previously said -1, 1, or 0, which was an overspecification,
as noted by Emre Hasegeli.  All of the existing callers appear to be fine
with the actual behavior, so just fix the comment.

In passing, improve infelicitous formatting of some call sites.
parent 99299756
...@@ -544,8 +544,8 @@ network_sub(PG_FUNCTION_ARGS) ...@@ -544,8 +544,8 @@ network_sub(PG_FUNCTION_ARGS)
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
PG_RETURN_BOOL(ip_bits(a1) > ip_bits(a2) PG_RETURN_BOOL(ip_bits(a1) > ip_bits(a2) &&
&& bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a2)) == 0); bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a2)) == 0);
} }
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
...@@ -559,8 +559,8 @@ network_subeq(PG_FUNCTION_ARGS) ...@@ -559,8 +559,8 @@ network_subeq(PG_FUNCTION_ARGS)
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
PG_RETURN_BOOL(ip_bits(a1) >= ip_bits(a2) PG_RETURN_BOOL(ip_bits(a1) >= ip_bits(a2) &&
&& bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a2)) == 0); bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a2)) == 0);
} }
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
...@@ -574,8 +574,8 @@ network_sup(PG_FUNCTION_ARGS) ...@@ -574,8 +574,8 @@ network_sup(PG_FUNCTION_ARGS)
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
PG_RETURN_BOOL(ip_bits(a1) < ip_bits(a2) PG_RETURN_BOOL(ip_bits(a1) < ip_bits(a2) &&
&& bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a1)) == 0); bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a1)) == 0);
} }
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
...@@ -589,8 +589,8 @@ network_supeq(PG_FUNCTION_ARGS) ...@@ -589,8 +589,8 @@ network_supeq(PG_FUNCTION_ARGS)
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
PG_RETURN_BOOL(ip_bits(a1) <= ip_bits(a2) PG_RETURN_BOOL(ip_bits(a1) <= ip_bits(a2) &&
&& bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a1)) == 0); bitncmp(ip_addr(a1), ip_addr(a2), ip_bits(a1)) == 0);
} }
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
...@@ -955,7 +955,7 @@ convert_network_to_scalar(Datum value, Oid typid) ...@@ -955,7 +955,7 @@ convert_network_to_scalar(Datum value, Oid typid)
* bitncmp(l, r, n) * bitncmp(l, r, n)
* compare bit masks l and r, for n bits. * compare bit masks l and r, for n bits.
* return: * return:
* -1, 1, or 0 in the libc tradition. * <0, >0, or 0 in the libc tradition.
* note: * note:
* network byte order assumed. this means 192.5.5.240/28 has * network byte order assumed. this means 192.5.5.240/28 has
* 0x11110000 in its fourth octet. * 0x11110000 in its fourth octet.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment