Add check for NULL subject to POSIX regexec().
diff --git a/ChangeLog b/ChangeLog
index 1a92b9a..a9e90b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,8 @@
10. Add null_subject and null_replacement modifiers to pcre2test.
+11. Add check for NULL subject to POSIX regexec() function.
+
Version 10.39 29-October-2021
-----------------------------
diff --git a/src/pcre2posix.c b/src/pcre2posix.c
index a5162df..647edcc 100644
--- a/src/pcre2posix.c
+++ b/src/pcre2posix.c
@@ -368,6 +368,8 @@
int options = 0;
pcre2_match_data *md = (pcre2_match_data *)preg->re_match_data;
+if (string == NULL) return REG_INVARG;
+
if ((eflags & REG_NOTBOL) != 0) options |= PCRE2_NOTBOL;
if ((eflags & REG_NOTEOL) != 0) options |= PCRE2_NOTEOL;
if ((eflags & REG_NOTEMPTY) != 0) options |= PCRE2_NOTEMPTY;
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 300c255..d5fde0d 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -771,7 +771,7 @@
PCRE2_NOTBOL|PCRE2_NOTEMPTY|PCRE2_NOTEOL)
#define POSIX_SUPPORTED_MATCH_CONTROLS (CTL_AFTERTEXT|CTL_ALLAFTERTEXT)
-#define POSIX_SUPPORTED_MATCH_CONTROLS2 (0)
+#define POSIX_SUPPORTED_MATCH_CONTROLS2 (CTL2_NULL_SUBJECT)
/* Control bits that are not ignored with 'push'. */
@@ -4106,7 +4106,7 @@
static void
show_controls(uint32_t controls, uint32_t controls2, const char *before)
{
-fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((controls & CTL_AFTERTEXT) != 0)? " aftertext" : "",
((controls & CTL_ALLAFTERTEXT) != 0)? " allaftertext" : "",
@@ -4136,6 +4136,8 @@
((controls & CTL_MEMORY) != 0)? " memory" : "",
((controls2 & CTL2_NL_SET) != 0)? " newline" : "",
((controls & CTL_NULLCONTEXT) != 0)? " null_context" : "",
+ ((controls2 & CTL2_NULL_REPLACEMENT) != 0)? " null_replacement" : "",
+ ((controls2 & CTL2_NULL_SUBJECT) != 0)? " null_subject" : "",
((controls & CTL_POSIX) != 0)? " posix" : "",
((controls & CTL_POSIX_NOSUB) != 0)? " posix_nosub" : "",
((controls & CTL_PUSH) != 0)? " push" : "",