[HACKERS] "left shift of negative value" warnings - Mailing list pgsql-hackers

From Andres Freund
Subject [HACKERS] "left shift of negative value" warnings
Date
Msg-id 20170409220102.4qvj4z64zkyxc74k@alap3.anarazel.de
Whole thread Raw
Responses Re: [HACKERS] "left shift of negative value" warnings  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

For a while I've been getting warnings like
/home/andres/src/postgresql/src/backend/utils/adt/inet_cidr_ntop.c: In function ‘inet_cidr_ntop_ipv6’:
/home/andres/src/postgresql/src/backend/utils/adt/inet_cidr_ntop.c:205:11: warning: left shift of negative value
[-Wshift-negative-value]  m = ~0 << (8 - b);          ^~
 
/home/andres/src/postgresql/src/backend/utils/adt/network.c: In function ‘inetmi’:
/home/andres/src/postgresql/src/backend/utils/adt/network.c:1482:24: warning: left shift of negative value
[-Wshift-negative-value]  res |= ((int64) -1) << (byte * 8);                       ^~
 
/home/andres/src/postgresql/src/backend/utils/adt/varbit.c: In function ‘bitfromint4’:
/home/andres/src/postgresql/src/backend/utils/adt/varbit.c:1546:16: warning: left shift of negative value
[-Wshift-negative-value]  val |= (-1) << (srcbitsleft + 8 - destbitsleft);               ^~
 
/home/andres/src/postgresql/src/backend/utils/adt/varbit.c: In function ‘bitfromint8’:
/home/andres/src/postgresql/src/backend/utils/adt/varbit.c:1626:16: warning: left shift of negative value
[-Wshift-negative-value]  val |= (-1) << (srcbitsleft + 8 - destbitsleft);
 

If I understand C99 correctly, the behaviour of a left-shift of a
negative number is undefined (6.5.7 4.).  In C89 the spec was very
unclear about that.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: [HACKERS] [sqlsmith] Planner crash on foreign table join
Next
From: Joe Conway
Date:
Subject: Re: [HACKERS] partitioned tables and contrib/sepgsql