]> git.tdb.fi Git - libs/gltk.git/commitdiff
Fix an unsigned overflow error in Text
authorMikko Rasa <tdb@tdb.fi>
Tue, 17 Sep 2019 12:36:33 +0000 (15:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 17 Sep 2019 12:36:33 +0000 (15:36 +0300)
source/text.cpp

index 1d824e0ddb9ca590f551748921503e626bcdd931..45b6567db5c640bcec37e0dfccee877323fde230 100644 (file)
@@ -123,8 +123,9 @@ unsigned Text::get_visible_lines(const Part &part, const Geometry &parent, unsig
        unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
 
        const Sides &margin = part.get_margin();
-       unsigned vmargin = margin.top+margin.bottom+line_height-line_spacing;
-       unsigned n_lines = min<unsigned>(lines.size(), max((max(parent.h, vmargin)-vmargin)/line_spacing, 1U));
+       unsigned vmargin = margin.top+margin.bottom;
+       unsigned free_height = max(parent.h, vmargin)-vmargin+line_spacing-line_height;
+       unsigned n_lines = min<unsigned>(lines.size(), max(free_height/line_spacing, 1U));
        if(fit_height)
                *fit_height = line_height+(n_lines-1)*line_spacing;