mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-16 19:00:58 +01:00
fix substring allocation
This commit is contained in:
20
engine.cc
20
engine.cc
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user