fix substring allocation

This commit is contained in:
2025-11-21 14:01:46 +01:00
parent 96b966892c
commit 314dafa164

View File

@@ -325,17 +325,20 @@ void Engine::regexp() {
cerr << "Token " << config.token << " did not produce sub strings!\n";
else {
ovector = pcre2_get_ovector_pointer(match_data);
const char *constline = const_cast<char*>(line.c_str());
for (int i = 0; i < num; i++) {
char * substring_start = const_cast<char*>(line.c_str()) + ovector[2*i];
for (int i = 1; i < num; i++) {
PCRE2_SPTR substring_start = (PCRE2_SPTR8)constline + ovector[2*i];
PCRE2_SIZE substring_length = ovector[2*i+1] - ovector[2*i];
if (i == 2) {
break;
}
subs[i] = substring_start;
char *part = (char *)malloc(substring_length+1);
part = strncpy(part, (char *)substring_start, substring_length);
subs[i-1] = part;
free(part);
}
if(config.reverse) {
value = subs[0];
key = subs[1];
@@ -348,7 +351,6 @@ void Engine::regexp() {
delete[] subs;
line = "";
}
value = encode(value);