From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Roman Kononov <kononov(at)ftml(dot)net> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #5237: strange int->bit and bit->int conversions |
Date: | 2009-12-12 19:00:20 |
Message-ID: | 9872.1260644420@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
Roman Kononov <kononov(at)ftml(dot)net> writes:
> 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.
Hm, you're right, it's definitely busted ...
> The patch re-implements the conversion functions.
... but I don't much care for this patch. It's unreadable, uncommented,
and doesn't even try to follow Postgres coding conventions.
It looks to me like the actual bug is that the "first fractional byte"
case ought to shift by destbitsleft - 8 not srcbitsleft - 8. A
secondary problem (which your patch fails to fix) is that if the
compiler chooses to implement signed >> as zero-fill rather than
sign-bit-fill (which it is allowed to do per C99) then we'll get
wrong, or at least not the desired, results. So I arrive at
the attached patch.
Unfortunately we've just missed the window for 8.4.2 etc, but I'll
get this committed for the next updates.
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
int-to-bit-2.patch | text/x-patch | 1.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Nagy Daniel | 2009-12-12 19:08:03 | Re: BUG #5238: frequent signal 11 segfaults |
Previous Message | Roman Kononov | 2009-12-12 16:59:47 | Re: BUG #5237: strange int->bit and bit->int conversions |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2009-12-12 19:17:48 | Re: BUG #5237: strange int->bit and bit->int conversions |
Previous Message | Tom Lane | 2009-12-12 17:38:29 | Re: XML schemas and PG column names |