diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c
index 65243bf..965386e 100644
--- a/src/pcre2_dfa_match.c
+++ b/src/pcre2_dfa_match.c
@@ -3522,6 +3522,12 @@ for (;;)
           if ((start_bits[c/8] & (1 << (c&7))) != 0) break;
           start_match++;
           }
+
+        /* See comment above in first_cu checking about the next line. */
+
+        if ((mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) == 0 &&
+            start_match >= mb->end_subject)
+          break;
         }
       }  /* End of first code unit handling */
 
diff --git a/src/pcre2_match.c b/src/pcre2_match.c
index c6b6975..34ce747 100644
--- a/src/pcre2_match.c
+++ b/src/pcre2_match.c
@@ -6526,6 +6526,14 @@ for(;;)
           if ((start_bits[c/8] & (1 << (c&7))) != 0) break;
           start_match++;
           }
+
+        /* See comment above in first_cu checking about the next few lines. */
+
+        if (!mb->partial && start_match >= mb->end_subject)
+          {
+          rc = MATCH_NOMATCH;
+          break;
+          }
         }
       }   /* End first code unit handling */