This patch fixes a segfault when .zsh_history contains commands starting
with `:` and longer than 15 characters long.
Considering the history line:
: 1592444398:0;:vspman epoll_ctl
The ranked item's line will be:
:vspman epoll_ctl
When building the prioritized history, we used to apply the zsh extended
history offset if the line starts with `:` (and if the command is longer
than `15`, defined by `ZSH_HISTORY_ITEM_OFFSET`), which then makes the
item point to:
tl
This makes the `r->item` pointer invalid, which causes the segfault
observed in #408 within `prioritized_history_destroy`.
---
This patch prevents the same issue from arising again (even if the
line is wrongly interpreted) since it avoids any pointer arithmetic
between assignment and freeing.
Additionally, the patch also greatly improves the heuristics used in
determining whether a line is of extended history format or not, since
the non-extended format is also supported by zsh.
---
Fix#410Fix#399