Skip to content

Commit

Permalink
Prevent search from wrapping infinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Sep 24, 2024
1 parent a92a042 commit 3efb426
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ui_curses.h"
#include "convert.h"
#include "options.h"
#include "debug.h"

struct searchable {
void *data;
Expand All @@ -39,7 +40,7 @@ static int advance(struct searchable *s, struct iter *iter,
*iter = s->head;
if (!s->ops.get_next(iter))
return 0;
*wrapped = 1;
*wrapped += 1;
}
} else {
if (!s->ops.get_prev(iter)) {
Expand All @@ -48,7 +49,7 @@ static int advance(struct searchable *s, struct iter *iter,
*iter = s->head;
if (!s->ops.get_prev(iter))
return 0;
*wrapped = 1;
*wrapped += 1;
}
}
return 1;
Expand Down Expand Up @@ -76,6 +77,15 @@ static int do_u_search(struct searchable *s, struct iter *iter, const char *text
}
if (!advance(s, iter, dir, &wrapped) || iters_equal(iter, &start))
return 0;
/**
* workaround for buggy implementations of search_ops where
* get_next/get_prev never equals the initial get_current
* (#1332)
*/
if (wrapped > 1) {
d_print("fixme: bailing since search wrapped more than once without a match\n");
return 0;
}
}
}

Expand Down

0 comments on commit 3efb426

Please sign in to comment.