mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-18 11:50:57 +01:00
fix substring allocation
This commit is contained in:
16
engine.cc
16
engine.cc
@@ -325,15 +325,18 @@ void Engine::regexp() {
|
|||||||
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
||||||
else {
|
else {
|
||||||
ovector = pcre2_get_ovector_pointer(match_data);
|
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];
|
|
||||||
|
|
||||||
if (i == 2) {
|
for (int i = 1; i < num; i++) {
|
||||||
break;
|
PCRE2_SPTR substring_start = (PCRE2_SPTR8)constline + ovector[2*i];
|
||||||
}
|
PCRE2_SIZE substring_length = ovector[2*i+1] - ovector[2*i];
|
||||||
|
|
||||||
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) {
|
if(config.reverse) {
|
||||||
@@ -348,7 +351,6 @@ void Engine::regexp() {
|
|||||||
|
|
||||||
delete[] subs;
|
delete[] subs;
|
||||||
|
|
||||||
|
|
||||||
line = "";
|
line = "";
|
||||||
}
|
}
|
||||||
value = encode(value);
|
value = encode(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user