Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9b53d96

Browse files
committed
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.
1 parent 514d4a1 commit 9b53d96

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/backend/utils/adt/inet_cidr_ntop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
202202
b = bits % 8;
203203
if (b != 0)
204204
{
205-
m = ~0 << (8 - b);
205+
m = ((u_int) ~0) << (8 - b);
206206
inbuf[p - 1] &= m;
207207
}
208208

src/backend/utils/adt/network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ inetmi(PG_FUNCTION_ARGS)
14861486
* have to do proper sign extension.
14871487
*/
14881488
if (carry == 0 && byte < sizeof(int64))
1489-
res |= ((int64) -1) << (byte * 8);
1489+
res |= ((uint64) (int64) -1) << (byte * 8);
14901490
}
14911491

14921492
PG_RETURN_INT64(res);

src/backend/utils/adt/varbit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,11 +1539,11 @@ bitfromint4(PG_FUNCTION_ARGS)
15391539
/* store first fractional byte */
15401540
if (destbitsleft > srcbitsleft)
15411541
{
1542-
int val = (int) (a >> (destbitsleft - 8));
1542+
unsigned int val = (unsigned int) (a >> (destbitsleft - 8));
15431543

15441544
/* Force sign-fill in case the compiler implements >> as zero-fill */
15451545
if (a < 0)
1546-
val |= (-1) << (srcbitsleft + 8 - destbitsleft);
1546+
val |= ((unsigned int) -1) << (srcbitsleft + 8 - destbitsleft);
15471547
*r++ = (bits8) (val & BITMASK);
15481548
destbitsleft -= 8;
15491549
}
@@ -1619,11 +1619,11 @@ bitfromint8(PG_FUNCTION_ARGS)
16191619
/* store first fractional byte */
16201620
if (destbitsleft > srcbitsleft)
16211621
{
1622-
int val = (int) (a >> (destbitsleft - 8));
1622+
unsigned int val = (unsigned int) (a >> (destbitsleft - 8));
16231623

16241624
/* Force sign-fill in case the compiler implements >> as zero-fill */
16251625
if (a < 0)
1626-
val |= (-1) << (srcbitsleft + 8 - destbitsleft);
1626+
val |= ((unsigned int) -1) << (srcbitsleft + 8 - destbitsleft);
16271627
*r++ = (bits8) (val & BITMASK);
16281628
destbitsleft -= 8;
16291629
}

0 commit comments

Comments
 (0)