syntect icon indicating copy to clipboard operation
syntect copied to clipboard

HighlightState with a non-empty initial_stack crashing?

Open yonilevy opened this issue 5 years ago • 2 comments

Hi,

I'm trying to build a HighlightState with a cached initial_stack, as described in the docs:

Alternatively you can save space by caching only the path field of this struct then re-create the HighlightState when needed by passing that stack as the initial_stack parameter to the new method. This takes less space but a small amount of time to re-create the style stack.

I'm probably missing something (very new to rust), but to me it appears this is guaranteed to crash: The first call to update_single_cache_for_push in HighlightState::new, will pass path of length 0, which results in path.len() - 1 panicking with attempt to subtract with overflow.

Is there an example somewhere of code using HighlightState with a non-empty initial_stack? What am I missing?

Thanks ahead, and many thanks for building this incredible library!

yonilevy avatar Sep 10 '19 14:09 yonilevy

Hi, thanks for reporting. It's possible that there are currently no unit tests covering this scenario, and that you are the first person to try using it... I will investigate when I'm able to make time, but maybe someone else will beat me to it :)

keith-hall avatar Sep 10 '19 15:09 keith-hall

Yup seems right, this path indeed doesn't seem to be tested. I might look into it this weekend if I have time, but no guarantees.

trishume avatar Sep 13 '19 01:09 trishume