Skip to content

Commit e606057

Browse files
committed
nemo-search-engine-advanced.c: Ensure that the final snippet
endpoint is no greater than the original endpoint. See inline comments - g_utf8_substring() cannot handle a start_pos greater than end_pos.
1 parent 8b9cdfc commit e606057

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libnemo-private/nemo-search-engine-advanced.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,11 @@ create_snippet (GMatchInfo *match_info,
725725

726726
// Extend the snipped forwards and back a bit to give context.
727727
new_start = MAX (0, start - SNIPPET_EXTEND_SIZE);
728-
new_end = MIN (end + SNIPPET_EXTEND_SIZE, total_length - 1);
728+
729+
// g_match_info_fetch_pos() can return an end_bytes that == total_length,
730+
// maybe a utf-8 encoding issue - g_utf8_substring can't deal with this,
731+
// so just clamp new_end to >= end.
732+
new_end = MIN (end + SNIPPET_EXTEND_SIZE, MAX (end, total_length - 1));
729733

730734
matched_str = g_match_info_fetch (match_info, 0);
731735

0 commit comments

Comments
 (0)