From e9d5b41888e591a5a25b2cf9a1cf4fab7ac5e7d2 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 7 Feb 2019 00:44:06 -0500 Subject: Check subexpressions with hi -c --- bin/hi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'bin/hi.c') diff --git a/bin/hi.c b/bin/hi.c index 5acca9b2..40f873d0 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -246,7 +246,20 @@ int main(int argc, char *argv[]) { regex_t regex = compile(Languages[i].pattern, REG_NOSUB); regfree(®ex); for (size_t j = 0; j < Languages[i].len; ++j) { - regex = compile(Languages[i].syntax[j].pattern, REG_NOSUB); + struct Syntax syn = Languages[i].syntax[j]; + regex = compile(syn.pattern, 0); + if (regex.re_nsub >= SubsLen) { + errx( + EX_SOFTWARE, + "too many subexpressions: %s", syn.pattern + ); + } + if (syn.subexp > regex.re_nsub) { + errx( + EX_SOFTWARE, + "no subexpression %zu: %s", syn.subexp, syn.pattern + ); + } regfree(®ex); } } -- cgit 1.4.1