From 3ddc932b0a808a4f5f55519ccf1d65f6caa41666 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 27 Jul 2018 11:36:00 +0300 Subject: Add warnings for unknown regex escape sequences. --- re.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 're.c') diff --git a/re.c b/re.c index eedd05ac..eefdfcd7 100644 --- a/re.c +++ b/re.c @@ -100,6 +100,12 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal) } } + const char *ok_to_escape; + if (do_traditional) + ok_to_escape = "()|*+?.^$\\[]/-"; + else + ok_to_escape = "<>`'BywWsS{}()|*+?.^$\\[]/-"; + /* We skip multibyte character, since it must not be a special character. */ if ((gawk_mb_cur_max == 1 || ! is_multibyte) && @@ -141,6 +147,14 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal) case '9': /* a\9b not valid */ *dest++ = c; src++; + { + static bool warned[2]; + + if (! warned[c - '8']) { + warning(_("regexp escape sequence `\\%c' treated as plain `%c'"), c, c); + warned[c - '8'] = true; + } + } break; case 'y': /* normally \b */ /* gnu regex op */ @@ -152,6 +166,14 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal) } /* else, fall through */ default: + if (strchr(ok_to_escape, c) == NULL) { + static bool warned[256]; + + if (! warned[c & 0xFF]) { + warning(_("regexp escape sequence `\\%c' is not a known regexp operator"), c); + warned[c & 0xFF] = true; + } + } *dest++ = '\\'; *dest++ = (char) c; src++; -- cgit v1.2.3