aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-01 00:17:33 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-01 00:17:33 +0100
commitbb6b8ce9146d77cbea6c37eeac0fd1e760061036 (patch)
treec31b40aeb9fd06f7f4d65b987b46fb1620474d6d /src/main.c
parent48b7c4478488046e190f8c9e5fa6bd4ddfb1018e (diff)
Introduce pcre2_bitch_and_die()
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c13
1 files changed, 4 insertions, 9 deletions
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