forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita1fb4bd
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 parent790be6f commita1fb4bd
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 | |
---|---|---|---|
| |||
1515 | 1515 |
| |
1516 | 1516 |
| |
1517 | 1517 |
| |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
1518 | 1539 |
| |
1519 | 1540 |
| |
1520 | 1541 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
451 | 451 |
| |
452 | 452 |
| |
453 | 453 |
| |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
454 | 460 |
| |
455 | 461 |
| |
456 | 462 |
| |
|
0 commit comments
Comments
(0)