From eaef1725d7ce3b41b87752a1e50f9a99d2021688 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 19 Aug 2022 22:52:19 -0400 Subject: [PATCH] Fixed source_line_index problem with a null context object --- peglib.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/peglib.h b/peglib.h index e6ae30f..6377d5c 100644 --- a/peglib.h +++ b/peglib.h @@ -496,6 +496,8 @@ struct SemanticValues : protected std::vector { // Line number and column at which the matched string is std::pair line_info() const { + if (!c_) { return std::pair(1, 1); } + auto &idx = source_line_index(); auto cur = static_cast(std::distance(ss, sv_.data())); @@ -2571,7 +2573,7 @@ inline size_t parse_literal(const char *s, size_t n, SemanticValues &vs, } inline const std::vector &SemanticValues::source_line_index() const { - if (!c_) { std::vector(); } + assert(c_); if (c_->source_line_index.empty()) { for (size_t pos = 0; pos < c_->l; pos++) { if (c_->s[pos] == '\n') { c_->source_line_index.push_back(pos); }