diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:17:33 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:17:33 +0100 |
commit | bb6b8ce9146d77cbea6c37eeac0fd1e760061036 (patch) | |
tree | c31b40aeb9fd06f7f4d65b987b46fb1620474d6d /src/main.c | |
parent | 48b7c4478488046e190f8c9e5fa6bd4ddfb1018e (diff) |
Introduce pcre2_bitch_and_die()
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -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 |