From bb6b8ce9146d77cbea6c37eeac0fd1e760061036 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 1 Nov 2024 00:17:33 +0100 Subject: Introduce pcre2_bitch_and_die() --- src/main.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 9e7e522..e004f1e 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include "exitcodes.h" #include "tpool.h" +#include "util.h" #include "work.h" #define MAIN_C 1 @@ -39,7 +40,6 @@ const char *lquot = "`", *rquot = "'"; matching or not */ typeof(pcre2_match) *pcre2_match_fn; -static char emsg[256]; /* Buffer for PCRE2 error messages */ /* TODO: Use the LUT in work.c */ static const bool opchars[] = { ['g'] = true, @@ -355,15 +355,10 @@ pattern_comp(u8view_t pat) int ec; size_t eoff; op.re = pcre2_compile(re.p, re.len, reopts, &ec, &eoff, nullptr); - if (op.re == nullptr) { - /* TODO: Ensure the buffer is large enough for the error message */ - (void)pcre2_get_error_message(ec, emsg, sizeof(emsg)); - cerr(EXIT_FATAL, "Failed to compile regex: %s", emsg); - } + if (op.re == nullptr) + pcre2_bitch_and_die(ec, "failed to compile regex: %s"); if ((ec = pcre2_jit_compile(op.re, PCRE2_JIT_COMPLETE)) != 0) { - /* TODO: Ensure the buffer is large enough for the error message */ - (void)pcre2_get_error_message(ec, emsg, sizeof(emsg)); - warn("Failed to JIT compile regex: %s", emsg); + pcre2_bitch_and_die(ec, "failed to JIT compile regex: %s"); rv = EXIT_WARNING; pcre2_match_fn = pcre2_match; } else -- cgit v1.2.3