Fix for being unable to match patterns on zero-length files (or at the

end of a file)
This commit is contained in:
Bruce Hill 2021-03-15 18:29:04 -07:00
parent 00bb63d277
commit f1499c9a63
2 changed files with 2 additions and 1 deletions

View File

@ -164,6 +164,7 @@ void destroy_file(file_t **f)
//
size_t get_line_number(file_t *f, const char *p)
{
if (f->nlines == 0) return 0;
// Binary search:
size_t lo = 0, hi = f->nlines-1;
while (lo <= hi) {

View File

@ -138,7 +138,7 @@ match_t *next_match(def_t *defs, file_t *f, match_t *prev, pat_t *pat, pat_t *sk
} else {
str = f->contents;
}
while (str < f->end) {
while (str <= f->end) {
match_t *m = match(defs, f, str, pat, ignorecase);
if (m) return m;
match_t *s;