postgresql/src/include/utils
Tom Lane 096d34c3ba 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 Generate fmgr prototypes automatically 2017-01-17 14:06:07 -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 Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
array.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:20 -07:00
arrayaccess.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:20 -07:00
ascii.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
attoptcache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
backend_random.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
builtins.h Fix some corner-case issues in REFRESH MATERIALIZED VIEW CONCURRENTLY. 2018-03-19 18:49:53 -04:00
bytea.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
cash.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
catcache.h Remove AtEOXact_CatCache(). 2017-08-13 16:15:14 -04:00
combocid.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
date.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
datetime.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
datum.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
dsa.h Use size_t consistently in dsa.{ch}. 2018-09-22 00:42:17 +12:00
dynahash.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
dynamic_loader.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
elog.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
evtcache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
expandeddatum.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:20 -07:00
fmgrtab.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
formatting.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
freepage.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
geo_decls.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
guc.h Teach SHOW ALL to honor pg_read_all_settings membership 2018-06-08 16:27:56 -04:00
guc_tables.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
hashutils.h Backport: Add inline murmurhash32(uint32) function. 2018-01-29 11:24:57 -08:00
help_config.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
hsearch.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
index_selfuncs.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
inet.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
int8.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
inval.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
json.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
jsonapi.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
jsonb.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
logtape.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
lsyscache.h Fix assorted bugs in pg_get_partition_constraintdef(). 2018-09-27 18:15:06 -04:00
memdebug.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
memutils.h Ensure SIZE_MAX can be used throughout our code. 2017-09-01 13:52:53 -04:00
nabstime.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
numeric.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
palloc.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pg_crc.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pg_locale.h Reject use of ucol_strcollUTF8() before ICU 53 2017-08-10 22:14:00 -04:00
pg_lsn.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pg_rusage.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pidfile.h Change pg_ctl to detect server-ready by watching status in postmaster.pid. 2017-06-28 17:31:32 -04:00
plancache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
portal.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
ps_status.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
queryenvironment.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rangetypes.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
regproc.h Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
rel.h Avoid catalog lookups in RelationAllowsEarlyPruning(). 2019-08-28 17:59:50 +12:00
relcache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
relfilenodemap.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
relmapper.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
relptr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
reltrigger.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
resowner.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
resowner_private.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rls.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
ruleutils.h Improve the error message when creating an empty range partition. 2017-08-10 13:46:56 -04:00
sampling.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
selfuncs.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
snapmgr.h Avoid catalog lookups in RelationAllowsEarlyPruning(). 2019-08-28 17:59:50 +12:00
snapshot.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
sortsupport.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:29 -04:00
spccache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
syscache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
timeout.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
timestamp.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tqual.h Fix low-probability loss of NOTIFY messages due to XID wraparound. 2017-10-11 14:28:33 -04:00
tuplesort.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tuplestore.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
typcache.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tzparser.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
uuid.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
varbit.h Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
varlena.h Further fixes for quoted-list GUC values in pg_dump and ruleutils.c. 2018-07-31 13:00:08 -04:00
xml.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00