Skip to content

Commit

Permalink
fix missing catch invalid_utf8_exception
Browse files Browse the repository at this point in the history
this caused crashes when loading certain replays.
  • Loading branch information
gfgtdf committed Dec 30, 2018
1 parent 21c20b9 commit 7875f4f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/font/sdl_ttf.cpp
Expand Up @@ -450,17 +450,22 @@ std::string make_text_ellipsis(const std::string &text, int font_size,

std::string current_substring;

utf8::iterator itor(text);
try {
utf8::iterator itor(text);
for(; itor != utf8::iterator::end(text); ++itor) {
std::string tmp = current_substring;
tmp.append(itor.substr().first, itor.substr().second);

for(; itor != utf8::iterator::end(text); ++itor) {
std::string tmp = current_substring;
tmp.append(itor.substr().first, itor.substr().second);
if (line_width(tmp + ellipsis, font_size, style) > max_width) {
return current_substring + ellipsis;
}

if (line_width(tmp + ellipsis, font_size, style) > max_width) {
return current_substring + ellipsis;
current_substring.append(itor.substr().first, itor.substr().second);
}

current_substring.append(itor.substr().first, itor.substr().second);
}
catch(utf8::invalid_utf8_exception&) {
WRN_FT << "Invalid UTF-8 string: \"" << text << "\"" << std::endl;
return "";
}

return text; // Should not happen
Expand Down

0 comments on commit 7875f4f

Please sign in to comment.