BUG #16790: Integer overflow not detected with <<

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com
Subject: BUG #16790: Integer overflow not detected with <<
Date: 2020-12-23 09:00:01
Message-ID: 16790-c2a81c92a8776c5b@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16790
Logged by: Alexander Lakhin
Email address: exclusion(at)gmail(dot)com
PostgreSQL version: 13.1
Operating system: Ubuntu 20.04
Description:

It seems that the bitwise shift left operator ignores overflow:
SELECT -1::int4<<32;
-1
But:
SELECT (-1::int4<<31) * 2;
ERROR: integer out of range

Is this an expected behavior (a kind of UB)? It's not like an arithmetic
shift. (The semantic of '1::int4<<-1' is questionable too.)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-12-23 15:29:56 Re: BUG #16790: Integer overflow not detected with <<
Previous Message Michael Paquier 2020-12-23 07:52:02 Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data