> Can this patch get committed in the current form? I don't mind committing either version of the patch.
Unless I hear objections, I'm going to commit the patch below soon. Index: re_search.c =================================================================== RCS file: /var/cvs/src/usr.bin/mg/re_search.c,v retrieving revision 1.33 diff -u -p -r1.33 re_search.c --- re_search.c 6 Aug 2017 04:39:45 -0000 1.33 +++ re_search.c 8 Jul 2020 13:00:40 -0000 @@ -332,8 +332,8 @@ re_forwsrch(void) while (clp != (curbp->b_headp)) { regex_match[0].rm_so = tbo; regex_match[0].rm_eo = llength(clp); - error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, - REG_STARTEND); + error = regexec(®ex_buff, ltext(clp) ? ltext(clp) : "", + RE_NMATCH, regex_match, REG_STARTEND); if (error != 0) { clp = lforw(clp); tdotline++; @@ -389,8 +389,9 @@ re_backsrch(void) * do this character-by-character after the first match since * POSIX regexps don't give you a way to do reverse matches. */ - while (!regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, - REG_STARTEND) && regex_match[0].rm_so < tbo) { + while (!regexec(®ex_buff, ltext(clp) ? ltext(clp) : "", + RE_NMATCH, regex_match, REG_STARTEND) && + regex_match[0].rm_so <= tbo) { memcpy(&lastmatch, ®ex_match[0], sizeof(regmatch_t)); regex_match[0].rm_so++; regex_match[0].rm_eo = llength(clp); @@ -538,8 +539,8 @@ killmatches(int cond) /* see if line matches */ regex_match[0].rm_so = 0; regex_match[0].rm_eo = llength(clp); - error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, - REG_STARTEND); + error = regexec(®ex_buff, ltext(clp) ? ltext(clp) : "", + RE_NMATCH, regex_match, REG_STARTEND); /* Delete line when appropriate */ if ((cond == FALSE && error) || (cond == TRUE && !error)) { @@ -613,8 +614,8 @@ countmatches(int cond) /* see if line matches */ regex_match[0].rm_so = 0; regex_match[0].rm_eo = llength(clp); - error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, - REG_STARTEND); + error = regexec(®ex_buff, ltext(clp) ? ltext(clp) : "", + RE_NMATCH, regex_match, REG_STARTEND); /* Count line when appropriate */ if ((cond == FALSE && error) || (cond == TRUE && !error))