postgresql/src/include/utils
Tom Lane 35eb132700 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
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h Fix missing role dependencies for some schema and type ACLs. 2018-11-09 20:42:03 -05:00
aclchk_internal.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
array.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:21 -07:00
arrayaccess.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:21 -07:00
ascii.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
attoptcache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
builtins.h Further fixes for quoted-list GUC values in pg_dump and ruleutils.c. 2018-07-31 13:00:08 -04:00
bytea.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h Remove AtEOXact_CatCache(). 2017-08-13 16:15:14 -04:00
combocid.h Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
date.h Fix incorrect translation of minus-infinity datetimes for json/jsonb. 2015-10-20 11:07:05 -07:00
datetime.h Fix incorrect translation of minus-infinity datetimes for json/jsonb. 2015-10-20 11:07:05 -07:00
datum.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
dynahash.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
dynamic_loader.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
elog.h Improve unreachability recognition in elog() macro. 2016-09-10 17:54:23 -04:00
evtcache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
expandeddatum.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:21 -07:00
fmgrtab.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
formatting.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
geo_decls.h Allow GiST distance function to return merely a lower-bound. 2015-05-15 14:26:51 +03:00
guc.h Fix mishandling of quoted-list GUC values in pg_dump and ruleutils.c. 2018-03-21 20:03:28 -04:00
guc_tables.h Group cluster_name and update_process_title settings together 2015-10-04 12:29:50 -04:00
help_config.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
hsearch.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
inet.h Add index-only scan support to inet GiST opclass. 2015-03-28 15:11:53 +02:00
int8.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
inval.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
json.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
jsonapi.h Support JSON negative array subscripts everywhere 2015-07-17 21:06:39 -04:00
jsonb.h Rename jsonb_replace to jsonb_set and allow it to add new values 2015-05-31 20:34:10 -04:00
logtape.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
lsyscache.h Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
memdebug.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
memutils.h Back-patch addition of the ALLOCSET_FOO_SIZES macros. 2018-10-12 14:49:33 -04:00
nabstime.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
numeric.h Remove bogus dependencies on NUMERIC_MAX_PRECISION. 2016-08-14 15:06:01 -04:00
palloc.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
pg_crc.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
pg_locale.h Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>. 2016-03-15 13:19:57 -04:00
pg_lsn.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_rusage.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
plancache.h Remove the SECURITY_ROW_LEVEL_DISABLED security context bit. 2015-09-20 20:47:36 -04:00
portal.h Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:37:16 -04:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
rel.h Re-allow user_catalog_table option for materialized views. 2016-11-10 15:00:58 -05:00
relcache.h Fix the logic for putting relations into the relcache init file. 2015-06-25 14:39:05 -04:00
relfilenodemap.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
relmapper.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
reltrigger.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
resowner.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
resowner_private.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
rls.h Remove the row_security=force GUC value. 2015-09-20 20:45:54 -04:00
ruleutils.h Fix handling of inherited check constraints in ALTER COLUMN TYPE (again). 2015-11-20 14:55:28 -05:00
sampling.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
selfuncs.h Add security checks to selectivity estimation functions 2017-05-08 09:19:07 -04:00
snapmgr.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
snapshot.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
sortsupport.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:30 -04:00
spccache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
syscache.h Avoid searching for callback functions in CallSyscacheCallbacks(). 2017-05-12 19:05:29 -04:00
timeout.h Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
timestamp.h Add transform functions for AT TIME ZONE. 2015-03-01 13:22:34 -05:00
tqual.h Fix low-probability loss of NOTIFY messages due to XID wraparound. 2017-10-11 14:28:33 -04:00
tuplesort.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tuplestore.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
typcache.h Fix handling of expanded objects in CoerceToDomain and CASE execution. 2016-12-22 15:01:39 -05:00
tzparser.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
uuid.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
varbit.h Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
xml.h Update copyright for 2015 2015-01-06 11:43:47 -05:00