postgresql/src
Tom Lane 8a17afe84b Fix failure to zero-pad the result of bitshiftright().
If the bitstring length is not a multiple of 8, we'd shift the
rightmost bits into the pad space, which must be zeroes --- bit_cmp,
for one, depends on that.  This'd lead to the result failing to
compare equal to what it should compare equal to, as reported in
bug #16013 from Daryl Waycott.

This is, if memory serves, not the first such bug in the bitstring
functions.  In hopes of making it the last one, do a bit more work
than minimally necessary to fix the bug:

* Add assertion checks to bit_out() and varbit_out() to complain if
they are given incorrectly-padded input.  This will improve the
odds that manual testing of any new patch finds problems.

* Encapsulate the padding-related logic in macros to make it
easier to use.

Also, remove unnecessary padding logic from bit_or() and bitxor().
Somebody had already noted that we need not re-pad the result of
bit_and() since the inputs are required to be the same length,
but failed to extrapolate that to the other two.

Also, move a comment block that once was near the head of varbit.c
(but people kept putting other stuff in front of it), to put it in
the header block.

Note for the release notes: if anyone has inconsistent data as a
result of saving the output of bitshiftright() in a table, it's
possible to fix it with something like
UPDATE mytab SET bitcol = ~(~bitcol) WHERE bitcol != ~(~bitcol);

This has been broken since day one, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/16013-c2765b6996aacae9@postgresql.org
2019-09-22 17:46:00 -04:00
..
backend Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
bin Handle corner cases correctly in psql's reconnection logic. 2019-09-02 14:02:46 -04:00
common Fix portability failure introduced in commits d2b0b60e7 et al. 2018-12-26 15:30:40 -05:00
include Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
interfaces Stamp 9.4.24. 2019-08-05 17:22:47 -04:00
makefiles Define WIN32_STACK_RLIMIT throughout win32 and cygwin builds. 2019-04-09 08:25:43 -07:00
pl Fix C++ incompatibilities in plpgsql's header files. 2019-05-31 12:34:55 -04:00
port Stamp 9.4.24. 2019-08-05 17:22:47 -04:00
template Yet further rethinking of build changes for macOS Mojave. 2018-11-02 18:54:00 -04:00
test Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
timezone Update time zone data files to tzdata release 2019c. 2019-09-20 19:54:36 -04:00
tools Improve handling of NULLs in KNN-GiST and KNN-SP-GiST 2019-09-19 22:10:46 +03:00
tutorial pgindent run for 9.4 2014-05-06 12:12:18 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Install TAP test infrastructure so it's available for extension testing. 2016-09-23 15:50:00 -04:00
Makefile.global.in Handle USE_MODULE_DB for all tests able to use an installed postmaster. 2019-04-03 17:10:42 -07:00
Makefile.shlib Ensure static libraries have correct mod time even if ranlib messes it up. 2018-11-29 15:53:44 -05:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00