Skip to content

Commit

Permalink
Remove NOT_REACHED from Layouter::GetCharPosition
Browse files Browse the repository at this point in the history
Return begin/end value for unknown code point index or out of range input

See: #596, #598, OpenTTD/OpenTTD#11291
  • Loading branch information
JGRennison committed Sep 26, 2023
1 parent d4ed088 commit aa4aee1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/gfx_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 };
}

/**
Expand Down

0 comments on commit aa4aee1

Please sign in to comment.