From 849d39783113dab5f3130e3e59cd8b30f53b136e Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 1 Nov 2024 20:48:33 +0100 Subject: Print the compile error offset --- src/main.c | 6 ++++-- src/util.c | 12 +++++++++--- src/util.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index f702842..a23ff56 100644 --- a/src/main.c +++ b/src/main.c @@ -343,8 +343,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) - pcre2_bitch_and_die(ec, "failed to compile regex: %s"); + if (op.re == nullptr) { + pcre2_bitch_and_die( + ec, "failed to compile regex at byte offset %zu: %s", eoff); + } if ((ec = pcre2_jit_compile(op.re, PCRE2_JIT_COMPLETE)) != 0) { pcre2_bitch_and_die(ec, "failed to JIT compile regex: %s"); rv = EXIT_WARNING; diff --git a/src/util.c b/src/util.c index bf18111..ae66bf9 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,10 +10,11 @@ #include "globals.h" void -pcre2_bitch_and_die(int ec, const char *fmt) +pcre2_bitch_and_die(int ec, const char *fmt, ...) { /* If we’ve gotten here, we don’t care about writing efficient code */ ptrdiff_t bufsz = 512; + for (;;) { char *buf = malloc(bufsz); if (buf == nullptr) @@ -20,8 +22,12 @@ pcre2_bitch_and_die(int ec, const char *fmt) if (pcre2_get_error_message(ec, buf, bufsz) == PCRE2_ERROR_NOMEMORY) { free(buf); bufsz *= 2; - } else - cerr(EXIT_FATAL, fmt, buf); + } else { + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + exit(EXIT_FATAL); + } } } diff --git a/src/util.h b/src/util.h index bb2ca16..705d0ee 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,6 @@ #define GRAB_UTIL_H int getenv_posnum(const char *ev, int fallback); -void pcre2_bitch_and_die(int ec, const char *fmt); +void pcre2_bitch_and_die(int ec, const char *fmt, ...); #endif /* !GRAB_UTIL_H */ \ No newline at end of file -- cgit v1.2.3