From e7f8e8eb1fd41b308ee10741bbd8068acc1847c2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 May 2022 12:38:42 -0700 Subject: grep: warn about stray backslashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This papers over a problem reported by Benno Schulenberg and Tomasz Dziendzielski involving regular expressions like \a that have unspecified behavior. * src/dfasearch.c (dfawarn): Just output a warning. Don’t exit, as DFA_CONFUSING_BRACKETS_ERROR now does that for us, and we need the ability to warn without exiting to diagnose \a etc. (GEAcompile): Use new dfa options DFA_CONFUSING_BRACKETS_ERROR and DFA_STRAY_BACKSLASH_WARN. --- src/dfasearch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/dfasearch.c b/src/dfasearch.c index 8f48296a..7547a8a3 100644 --- a/src/dfasearch.c +++ b/src/dfasearch.c @@ -53,10 +53,10 @@ dfaerror (char const *mesg) die (EXIT_TROUBLE, 0, "%s", mesg); } -_Noreturn void +void dfawarn (char const *mesg) { - dfaerror (mesg); + error (0, 0, _("warning: %s"), mesg); } /* If the DFA turns out to have some set of fixed strings one of @@ -196,7 +196,8 @@ GEAcompile (char *pattern, idx_t size, reg_syntax_t syntax_bits, if (match_icase) syntax_bits |= RE_ICASE; - int dfaopts = eolbyte ? 0 : DFA_EOL_NUL; + int dfaopts = (DFA_CONFUSING_BRACKETS_ERROR | DFA_STRAY_BACKSLASH_WARN + | (eolbyte ? 0 : DFA_EOL_NUL)); dfasyntax (dc->dfa, &localeinfo, syntax_bits, dfaopts); bool bs_safe = !localeinfo.multibyte | localeinfo.using_utf8; -- cgit v1.2.1