Skip to content

Commit

Permalink
Add missing NUL check
Browse files Browse the repository at this point in the history
If the query is empty the first call to strcasechr() in min_match() will try to
find a NUL-byte in all choices which it never will due to loop condition
`choice[i] != '\0'`. Therefore, add a missing NUL-check just like in the loop
below. This should speed up startup time.
  • Loading branch information
mptre committed Feb 18, 2018
1 parent 4407f49 commit 1786606
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ min_match(const char *string, size_t offset, ssize_t *start, ssize_t *end)
size_t length;

q = query;
if ((s = e = strcasechr(&string[offset], q)) == NULL)
if (*q == '\0' || (s = e = strcasechr(&string[offset], q)) == NULL)
return INT_MAX;

for (;;) {
Expand Down

0 comments on commit 1786606

Please sign in to comment.