1
1
mirror of https://github.com/tstack/lnav.git synced 2024-11-10 21:59:10 +03:00

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.
This commit is contained in:
Phil Hord 2018-03-27 09:15:54 -07:00
parent 9e8efae48e
commit 4d1d782007
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -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) {