forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf976a77
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 parent2624de7 commitf976a77
File tree
3 files changed
+33
-2
lines changed- src
- backend/tsearch
- test/regress
- expected
- sql
3 files changed
+33
-2
lines changedLines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2038 | 2038 |
| |
2039 | 2039 |
| |
2040 | 2040 |
| |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
2041 | 2044 |
| |
2042 | 2045 |
| |
2043 | 2046 |
| |
| |||
2342 | 2345 |
| |
2343 | 2346 |
| |
2344 | 2347 |
| |
2345 |
| - | |
| 2348 | + | |
| 2349 | + | |
2346 | 2350 |
| |
2347 | 2351 |
| |
2348 | 2352 |
| |
| |||
2497 | 2501 |
| |
2498 | 2502 |
| |
2499 | 2503 |
| |
2500 |
| - | |
| 2504 | + | |
2501 | 2505 |
| |
2502 | 2506 |
| |
2503 | 2507 |
| |
|
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2000 | 2000 |
| |
2001 | 2001 |
| |
2002 | 2002 |
| |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
2003 | 2024 |
| |
2004 | 2025 |
| |
2005 | 2026 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
563 | 563 |
| |
564 | 564 |
| |
565 | 565 |
| |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
566 | 572 |
| |
567 | 573 |
| |
568 | 574 |
| |
|
0 commit comments
Comments
(0)