From 6c7dcfc4a61128d480dbf3aa4eaf26ee4509ccb6 Mon Sep 17 00:00:00 2001 From: Finn Barber Date: Wed, 21 Aug 2024 11:21:56 +0100 Subject: [PATCH] Fix segfaults with Regex-match --- src/runtime.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/runtime.h b/src/runtime.h index 48be4cc..90e1ed6 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -1490,15 +1490,13 @@ static BLOCK ___regex(STRING reg_str) void match_regex(uint8_t* env) { - regex_t reg = *(regex_t*)env; + regex_t* reg = (regex_t*)env; STRING str = unbox_STRING(pop()); - size_t groups = reg.re_nsub + 1; + size_t groups = reg->re_nsub + 1; regmatch_t matches[groups]; - const int found = regexec(®, str, groups, matches, 0); - if unlikely(found != 0 && found != REG_NOMATCH) - throw_error_fmt("Regex failed matching string '%.32s'", str); + const int found = regexec(reg, str, groups, matches, 0); + if unlikely(found != 0 && found != REG_NOMATCH) throw_error_fmt("Regex failed matching string '%.32s'", str); - LIST lst = NULL; if (found == 0) { for (unsigned int g = 1; g < groups ; g++) { @@ -1524,7 +1522,7 @@ void match_regex(uint8_t* env) static BLOCK ___regexDmatch(STRING reg_str) { - regex_t* reg = gc_flatmalloc(sizeof(reg)); + regex_t* reg = gc_flatmalloc(sizeof *reg); const int status = regcomp(reg, reg_str, REG_EXTENDED | REG_NEWLINE); errno = 0; if unlikely(status)