From 783441b1d36c18c22015d283045a38bb108390ba Mon Sep 17 00:00:00 2001 From: Nathan Craddock Date: Tue, 15 Mar 2022 13:28:37 -0600 Subject: [PATCH] fix: missing null check The name was used assuming it was not null, so using the --plain option would crash before this. Caught in telescope-zf-native.nvim. --- src/filter.zig | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/filter.zig b/src/filter.zig index da65d2d..01324ca 100644 --- a/src/filter.zig +++ b/src/filter.zig @@ -191,16 +191,20 @@ pub fn rankToken( ) ?f64 { // iterate over the indexes where the first char of the token matches var best_rank: ?f64 = null; - var it = IndexIterator.init(name.?, token[0], smart_case); - - const offs = str.len - name.?.len; - while (it.next()) |start_index| { - if (scanToEnd(name.?, token[1..], start_index, smart_case)) |match| { - if (best_rank == null or match.rank < best_rank.?) { - best_rank = match.rank; - range.* = .{ .start = match.start + offs, .end = match.end + offs }; - } - } else break; + + var it: IndexIterator = undefined; + if (name != null) { + it = IndexIterator.init(name.?, token[0], smart_case); + const offs = str.len - name.?.len; + + while (it.next()) |start_index| { + if (scanToEnd(name.?, token[1..], start_index, smart_case)) |match| { + if (best_rank == null or match.rank < best_rank.?) { + best_rank = match.rank; + range.* = .{ .start = match.start + offs, .end = match.end + offs }; + } + } else break; + } } if (best_rank != null) {