1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00

fix(cairo): Fix font prioritization

In the previous implementation, std::find() returned fns.end() several times,
which caused an "Address boundary error" in std::sort if the preferred
font-index was set to m_fonts.size() + 1.

This commit reimplements the font prioritization with a simple swap.

Reproduction steps:

- Start polybar with the following config:

  [bar/top]
  font-0 = NotoSans-Regular:size=8;0
  font-1 = MaterialIcons:size=10;0

  modules-left = date

  [module/date]
  type = internal/date
  date = %Y-%m-%d
  label-font = 3 ; invalid index
This commit is contained in:
László Várady 2017-01-28 23:26:42 +01:00 committed by Michael Carlberg
parent 8a98fb78b6
commit 701102d44b

View file

@ -145,16 +145,12 @@ namespace cairo {
double x, y; double x, y;
position(&x, &y); position(&x, &y);
// Sort the fontlist so that the // Prioritize the preferred font
// preferred font gets prioritized
vector<shared_ptr<font>> fns(m_fonts.begin(), m_fonts.end()); vector<shared_ptr<font>> fns(m_fonts.begin(), m_fonts.end());
std::sort(fns.begin(), fns.end(), [&](const shared_ptr<font>& a, const shared_ptr<font>&) {
if (t.font > 0 && std::distance(fns.begin(), std::find(fns.begin(), fns.end(), a)) == t.font - 1) { if (t.font > 0 && t.font <= std::distance(fns.begin(), fns.end())) {
return -1; std::iter_swap(fns.begin(), fns.begin() + t.font - 1);
} else {
return 0;
} }
});
string utf8 = string(t.contents); string utf8 = string(t.contents);
utils::unicode_charlist chars; utils::unicode_charlist chars;