forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit029dea8
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 parent18103b7 commit029dea8
File tree
3 files changed
+41
-7
lines changed- src
- backend/tsearch
- test/regress
- expected
- sql
3 files changed
+41
-7
lines changedLines changed: 14 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2417 | 2417 |
| |
2418 | 2418 |
| |
2419 | 2419 |
| |
2420 |
| - | |
| 2420 | + | |
| 2421 | + | |
2421 | 2422 |
| |
2422 | 2423 |
| |
2423 | 2424 |
| |
| |||
2571 | 2572 |
| |
2572 | 2573 |
| |
2573 | 2574 |
| |
2574 |
| - | |
| 2575 | + | |
2575 | 2576 |
| |
2576 | 2577 |
| |
2577 | 2578 |
| |
| |||
2601 | 2602 |
| |
2602 | 2603 |
| |
2603 | 2604 |
| |
2604 |
| - | |
2605 | 2605 |
| |
2606 | 2606 |
| |
2607 | 2607 |
| |
| |||
2671 | 2671 |
| |
2672 | 2672 |
| |
2673 | 2673 |
| |
2674 |
| - | |
2675 |
| - | |
2676 |
| - | |
2677 |
| - | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
2678 | 2685 |
| |
2679 | 2686 |
| |
2680 | 2687 |
| |
|
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2127 | 2127 |
| |
2128 | 2128 |
| |
2129 | 2129 |
| |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
2130 | 2151 |
| |
2131 | 2152 |
| |
2132 | 2153 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
640 | 640 |
| |
641 | 641 |
| |
642 | 642 |
| |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
643 | 649 |
| |
644 | 650 |
| |
645 | 651 |
| |
|
0 commit comments
Comments
(0)