forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb7d6c51
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 parentb02bf1e commitb7d6c51
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 | |
---|---|---|---|
| |||
2046 | 2046 |
| |
2047 | 2047 |
| |
2048 | 2048 |
| |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
2049 | 2052 |
| |
2050 | 2053 |
| |
2051 | 2054 |
| |
| |||
2350 | 2353 |
| |
2351 | 2354 |
| |
2352 | 2355 |
| |
2353 |
| - | |
| 2356 | + | |
| 2357 | + | |
2354 | 2358 |
| |
2355 | 2359 |
| |
2356 | 2360 |
| |
| |||
2505 | 2509 |
| |
2506 | 2510 |
| |
2507 | 2511 |
| |
2508 |
| - | |
| 2512 | + | |
2509 | 2513 |
| |
2510 | 2514 |
| |
2511 | 2515 |
| |
|
Lines changed: 21 additions & 0 deletions
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 |
| |
|
Lines changed: 6 additions & 0 deletions
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)