Show error message when `pcre2_match` fails

This commit is contained in:
Guldoman 2021-10-11 22:20:44 +02:00
parent 3a71528087
commit 038e335c8c
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 5 additions and 2 deletions

View File

@ -68,8 +68,11 @@ static int f_pcre_match(lua_State *L) {
int rc = pcre2_match(re, (PCRE2_SPTR)str, len, offset - 1, opts, md, NULL);
if (rc < 0) {
pcre2_match_data_free(md);
if (rc != PCRE2_ERROR_NOMATCH)
luaL_error(L, "regex matching error %d", rc);
if (rc != PCRE2_ERROR_NOMATCH) {
PCRE2_UCHAR buffer[120];
pcre2_get_error_message(rc, buffer, sizeof(buffer));
luaL_error(L, "regex matching error %d: %s", rc, buffer);
}
return 0;
}
PCRE2_SIZE* ovector = pcre2_get_ovector_pointer(md);