forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit34ad3ae
committed
Fix ts_headline() edge cases for empty query and empty search text.
tsquery's GETQUERY() macro is only safe to apply to a tsquerythat is known non-empty; otherwise it gives a pointer to garbage.Before commit5a617d7, ts_headline() avoided this pitfall, butonly in a very indirect, nonobvious way. (hlCover could not reachits TS_execute call, because if the query contains no lexemesthen 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 anempty query. In the back branches, add a defensive check tohlCover() --- that's not fixing any live bug, but I judge thecode a bit too fragile as-is.Also, both mark_hl_fragments() and mark_hl_words() were carelessabout the possibility of empty search text: in the cases whereno match has been found, they'd end up telling mark_fragment() tomark from word indexes 0 to 0 inclusive, even when there is noword 0. This is harmless since we over-allocated the prs->wordsarray, but it does annoy valgrind. Fix so that the end index is -1and thus mark_fragment() will do nothing in such cases.Bottom line is that this fixes a live bug in HEAD, but in theback 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.com1 parent0a6aaf0 commit34ad3ae
File tree
3 files changed
+33
-2
lines changed- src
- backend/tsearch
- test/regress
- expected
- sql
3 files changed
+33
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2039 | 2039 | | |
2040 | 2040 | | |
2041 | 2041 | | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
2042 | 2045 | | |
2043 | 2046 | | |
2044 | 2047 | | |
| |||
2343 | 2346 | | |
2344 | 2347 | | |
2345 | 2348 | | |
2346 | | - | |
| 2349 | + | |
| 2350 | + | |
2347 | 2351 | | |
2348 | 2352 | | |
2349 | 2353 | | |
| |||
2498 | 2502 | | |
2499 | 2503 | | |
2500 | 2504 | | |
2501 | | - | |
| 2505 | + | |
2502 | 2506 | | |
2503 | 2507 | | |
2504 | 2508 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1990 | 1990 | | |
1991 | 1991 | | |
1992 | 1992 | | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
1993 | 2014 | | |
1994 | 2015 | | |
1995 | 2016 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
552 | 558 | | |
553 | 559 | | |
554 | 560 | | |
| |||
0 commit comments
Comments
(0)