diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index a17ef42f1c..729daa402e 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -230,10 +230,13 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const const auto &line = this->front(); /* Pointer to the end-of-string marker? Return total line width. */ - if (ch == this->string.end()) { + if (ch >= this->string.end()) { Point p = { line->GetWidth(), 0 }; return p; } + if (ch < this->string.begin()) { + return { 0, 0 }; + } /* Find the code point index which corresponds to the char * pointer into our UTF-8 source string. */ @@ -264,7 +267,8 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const } } - NOT_REACHED(); + /* Code point index not found, just give up */ + return { 0, 0 }; } /**