aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-03-15 18:29:04 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-03-15 18:29:04 -0700
commitf1499c9a6356269d0cbc96df52689a743e2d263c (patch)
tree56f239586c70480c6d5d3813f0cb7e91a5664c82
parent00bb63d27708a9ba7f7e5abe04c88fa6e01149fa (diff)
Fix for being unable to match patterns on zero-length files (or at the
end of a file)
-rw-r--r--files.c1
-rw-r--r--match.c2
2 files changed, 2 insertions, 1 deletions
diff --git a/files.c b/files.c
index 4192f9e..1bde7b4 100644
--- a/files.c
+++ b/files.c
@@ -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) {
diff --git a/match.c b/match.c
index e675679..dd9492f 100644
--- a/match.c
+++ b/match.c
@@ -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;