diff --git a/src/grep.c b/src/grep.c
index e289095..062eb9a 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1086,6 +1086,9 @@ grepbuf (char const *beg, char const *lim)
       /* Avoid matching the empty line at the end of the buffer. */
       if (b == lim)
        break;
+      if (!match_size) {
+         p = endp; continue;
+      }
       if (!out_invert)
        {
          prtext (b, endp, (int *) 0);
