Re: BUG #5237: strange int->bit and bit->int conversions

From: Roman Kononov <kononov(at)ftml(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5237: strange int->bit and bit->int conversions
Date: 2009-12-12 16:59:47
Message-ID: 4B23CC03.50408@ftml.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

The bitfromint8() and bitfromint4() are hosed. They produce wrong
results when the BIT size is more than 64 and 32 respectively, and the
BIT size is not multiple of 8, and the most significant byte of the
integer value is not 0x00 or 0xff.

For example:

test=# select (11::int4<<23 | 11::int4)::bit(32);
00000101100000000000000000001011

test=# select (11::int4<<23 | 11::int4)::bit(33);
000001011100000000000000000001011

test=# select (11::int4<<23 | 11::int4)::bit(39);
000001010000101100000000000000000001011

test=# select (11::int4<<23 | 11::int4)::bit(40);
0000000000000101100000000000000000001011

The ::bit(33) and ::bit(39) conversions are wrong.

The patch re-implements the conversion functions.

Attachment Content-Type Size
int-to-bit.patch text/x-patch 3.7 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2009-12-12 19:00:20 Re: BUG #5237: strange int->bit and bit->int conversions
Previous Message Tom Lane 2009-12-12 15:12:19 Re: BUG #5238: frequent signal 11 segfaults

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2009-12-12 17:10:24 Re: Adding support for SE-Linux security
Previous Message Magnus Hagander 2009-12-12 16:58:47 Winflex