string2level uses wrong string length

It should pass only the matched length, not the original string length.
Caught by -fsanitize=address while trying to parse "some string (DEBUG)"
Probaby deserves a unit test.
pull/506/head
Phil Hord 7 years ago
parent 9e8efae48e
commit 4d1d782007

@ -108,7 +108,8 @@ logline::level_t logline::string2level(const char *levelstr, ssize_t len, bool e
pcre_context_static<10> pc;
if (LEVEL_RE.match(pc, pi)) {
retval = abbrev2level(pi.get_substr_start(pc.begin()), len);
auto iter = pc.begin();
retval = abbrev2level(pi.get_substr_start(iter), pi.get_substr_len(iter));
}
return retval;

@ -227,6 +227,11 @@ public:
return &this->pi_string[iter->c_begin];
};
size_t get_substr_len(pcre_context::const_iterator iter) const
{
return iter->length();
};
std::string get_substr(pcre_context::const_iterator iter) const
{
if (iter->c_begin == -1) {

Loading…
Cancel
Save