Commit 9b53d966 authored by Tom Lane's avatar Tom Lane

Suppress -Wshift-negative-value warnings.

Clean up four places that result in compiler warnings when using recent
gcc with this warning class enabled (as seen on buildfarm members
calliphoridae, skink, and others).  In all these places, this is purely
cosmetic, because the shift distance could not be large enough to risk
a change of sign, so there's no chance of implementation-dependent
behavior.  Still, it's easy enough to avoid the warning by casting the
shifted value to unsigned, so let's do that.

Patch HEAD only, this isn't worth a back-patch.
parent 514d4a13
...@@ -202,7 +202,7 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) ...@@ -202,7 +202,7 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
b = bits % 8; b = bits % 8;
if (b != 0) if (b != 0)
{ {
m = ~0 << (8 - b); m = ((u_int) ~0) << (8 - b);
inbuf[p - 1] &= m; inbuf[p - 1] &= m;
} }
......
...@@ -1486,7 +1486,7 @@ inetmi(PG_FUNCTION_ARGS) ...@@ -1486,7 +1486,7 @@ inetmi(PG_FUNCTION_ARGS)
* have to do proper sign extension. * have to do proper sign extension.
*/ */
if (carry == 0 && byte < sizeof(int64)) if (carry == 0 && byte < sizeof(int64))
res |= ((int64) -1) << (byte * 8); res |= ((uint64) (int64) -1) << (byte * 8);
} }
PG_RETURN_INT64(res); PG_RETURN_INT64(res);
......
...@@ -1539,11 +1539,11 @@ bitfromint4(PG_FUNCTION_ARGS) ...@@ -1539,11 +1539,11 @@ bitfromint4(PG_FUNCTION_ARGS)
/* store first fractional byte */ /* store first fractional byte */
if (destbitsleft > srcbitsleft) if (destbitsleft > srcbitsleft)
{ {
int val = (int) (a >> (destbitsleft - 8)); unsigned int val = (unsigned int) (a >> (destbitsleft - 8));
/* Force sign-fill in case the compiler implements >> as zero-fill */ /* Force sign-fill in case the compiler implements >> as zero-fill */
if (a < 0) if (a < 0)
val |= (-1) << (srcbitsleft + 8 - destbitsleft); val |= ((unsigned int) -1) << (srcbitsleft + 8 - destbitsleft);
*r++ = (bits8) (val & BITMASK); *r++ = (bits8) (val & BITMASK);
destbitsleft -= 8; destbitsleft -= 8;
} }
...@@ -1619,11 +1619,11 @@ bitfromint8(PG_FUNCTION_ARGS) ...@@ -1619,11 +1619,11 @@ bitfromint8(PG_FUNCTION_ARGS)
/* store first fractional byte */ /* store first fractional byte */
if (destbitsleft > srcbitsleft) if (destbitsleft > srcbitsleft)
{ {
int val = (int) (a >> (destbitsleft - 8)); unsigned int val = (unsigned int) (a >> (destbitsleft - 8));
/* Force sign-fill in case the compiler implements >> as zero-fill */ /* Force sign-fill in case the compiler implements >> as zero-fill */
if (a < 0) if (a < 0)
val |= (-1) << (srcbitsleft + 8 - destbitsleft); val |= ((unsigned int) -1) << (srcbitsleft + 8 - destbitsleft);
*r++ = (bits8) (val & BITMASK); *r++ = (bits8) (val & BITMASK);
destbitsleft -= 8; destbitsleft -= 8;
} }
......
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