diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-03-13 07:14:33 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-03-13 07:14:33 +1100 |
| commit | c956413046ae1a57ab4dab9dee6986ec3e0eb2a6 (patch) | |
| tree | 43aab1b226c3576cf2810ba5559861642b6415d1 /src | |
| parent | b06834bf47d798e4a57d107543df9446958f0220 (diff) | |
Fix quantifier parsing bug
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex_impl.cc | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 4290289d..33d7a88a 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -541,13 +541,13 @@ private: return {1, 1}; constexpr int max_repeat = 1000; - auto read_bound = [&]() { + auto read_bound = [&]() -> Optional<int16_t> { int16_t res = 0; for (auto begin = m_pos; m_pos != m_regex.end(); ++m_pos) { const auto cp = *m_pos; if (cp < '0' or cp > '9') - return m_pos == begin ? (int16_t)-1 : res; + return m_pos == begin ? Optional<int16_t>{} : res; res = res * 10 + cp - '0'; if (res > max_repeat) parse_error(format("Explicit quantifier is too big, maximum is {}", max_repeat)); @@ -570,14 +570,12 @@ private: case '{': { ++m_pos; - const int16_t min = read_bound(); + const int16_t min = read_bound().value_or(int16_t{}); int16_t max = min; if (*m_pos == ',') { ++m_pos; - max = read_bound(); - if (max == -1) - max = ParsedRegex::Quantifier::infinite; + max = read_bound().value_or(ParsedRegex::Quantifier::infinite); } if (*m_pos++ != '}') parse_error("expected closing bracket"); |
