postgresql/src/backend
Tom Lane 029dea882a Fix ts_headline() edge cases for empty query and empty search text.
tsquery's GETQUERY() macro is only safe to apply to a tsquery
that is known non-empty; otherwise it gives a pointer to garbage.
Before commit 5a617d75d, ts_headline() avoided this pitfall, but
only in a very indirect, nonobvious way.  (hlCover could not reach
its TS_execute call, because if the query contains no lexemes
then hlFirstIndex would surely return -1.)  After that commit,
it fell into the trap, resulting in weird errors such as
"unrecognized operator" and/or valgrind complaints.  In HEAD,
fix this by not calling TS_execute_locations() at all for an
empty query.  In the back branches, add a defensive check to
hlCover() --- that's not fixing any live bug, but I judge the
code a bit too fragile as-is.

Also, both mark_hl_fragments() and mark_hl_words() were careless
about the possibility of empty search text: in the cases where
no match has been found, they'd end up telling mark_fragment() to
mark from word indexes 0 to 0 inclusive, even when there is no
word 0.  This is harmless since we over-allocated the prs->words
array, but it does annoy valgrind.  Fix so that the end index is -1
and thus mark_fragment() will do nothing in such cases.

Bottom line is that this fixes a live bug in HEAD, but in the
back branches it's only getting rid of a valgrind nitpick.
Back-patch anyway.

Per report from Alexander Lakhin.

Discussion: https://postgr.es/m/c27f642d-020b-01ff-ae61-086af287c4fd@gmail.com
2023-04-06 15:52:44 -04:00
..
access hio: Don't pin the VM while holding buffer lock while extending 2023-04-06 11:11:13 -07:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Support long distance matching for zstd compression 2023-04-06 17:18:42 +02:00
bootstrap Fix CREATE INDEX progress reporting for multi-level partitioning. 2023-03-25 15:34:03 -04:00
catalog Update information_schema for SQL:2023 2023-04-05 09:57:44 +02:00
commands Move various prechecks from vacuum() into ExecVacuum() 2023-04-06 15:44:52 +12:00
executor Fix row tracking in pg_stat_statements with extended query protocol 2023-04-06 09:29:03 +09:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit SQL/JSON: support the IS JSON predicate 2023-03-31 22:34:04 +02:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq Make SCRAM iteration count configurable 2023-03-27 09:46:29 +02:00
main Mark options as deprecated in usage output 2023-03-02 14:36:37 +01:00
nodes Code review for recent SQL/JSON commits 2023-04-04 14:04:30 +02:00
optimizer Support "Right Anti Join" plan shapes. 2023-04-05 16:59:09 -04:00
parser Code review for recent SQL/JSON commits 2023-04-04 14:04:30 +02:00
partitioning Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
po meson: add install-{quiet, world} targets 2023-03-23 21:20:18 -07:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
postmaster Move various prechecks from vacuum() into ExecVacuum() 2023-04-06 15:44:52 +12:00
regex Refactor to introduce pg_locale_deterministic(). 2023-02-23 11:17:41 -08:00
replication Add a run_as_owner option to subscriptions. 2023-04-04 12:03:03 -04:00
rewrite Fix more bugs caused by adding columns to the end of a view. 2023-03-07 18:21:53 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
storage Use ExtendBufferedRelTo() in {vm,fsm}_extend() 2023-04-05 17:50:09 -07:00
tcop When using valgrind, log the current query after an error is detected. 2023-04-03 10:18:38 -04:00
tsearch Fix ts_headline() edge cases for empty query and empty search text. 2023-04-06 15:52:44 -04:00
utils bufmgr: Introduce infrastructure for faster relation extension 2023-04-05 16:21:09 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Redesign archive modules 2023-02-17 14:26:42 +09:00
meson.build meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00