Fix TTF iteration in case of an empty list.

This commit is contained in:
Ryan Pavlik 2019-08-20 11:23:09 -05:00 committed by whitequark
parent 15838dc5a1
commit 61c0167ad7

View File

@ -72,12 +72,12 @@ void TtfFontList::LoadAll() {
} }
// Sort fonts according to their actual name, not filename. // Sort fonts according to their actual name, not filename.
std::sort(&l[0], &l[l.n], std::sort(l.begin(), l.end(),
[](const TtfFont &a, const TtfFont &b) { return a.name < b.name; }); [](const TtfFont &a, const TtfFont &b) { return a.name < b.name; });
// Filter out fonts with the same family and style name. This is not // Filter out fonts with the same family and style name. This is not
// strictly necessarily the exact same font, but it will almost always be. // strictly necessarily the exact same font, but it will almost always be.
TtfFont *it = std::unique(&l[0], &l[l.n], TtfFont *it = std::unique(l.begin(), l.end(),
[](const TtfFont &a, const TtfFont &b) { return a.name == b.name; }); [](const TtfFont &a, const TtfFont &b) { return a.name == b.name; });
l.RemoveLast(&l[l.n] - it); l.RemoveLast(&l[l.n] - it);