Skip to content

Commit

Permalink
fix: missing null check
Browse files Browse the repository at this point in the history
The name was used assuming it was not null, so using the --plain option
would crash before this. Caught in telescope-zf-native.nvim.
  • Loading branch information
natecraddock committed Mar 15, 2022
1 parent 8f08ad4 commit 783441b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/filter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 783441b

Please sign in to comment.