From: Mikko Rasa Date: Tue, 17 Sep 2019 12:36:33 +0000 (+0300) Subject: Fix an unsigned overflow error in Text X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=8bc33895d1bb04adcefee405746ef3c21d99a66d Fix an unsigned overflow error in Text --- diff --git a/source/text.cpp b/source/text.cpp index 1d824e0..45b6567 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -123,8 +123,9 @@ unsigned Text::get_visible_lines(const Part &part, const Geometry &parent, unsig unsigned line_spacing = static_cast(font_size*6/5); const Sides &margin = part.get_margin(); - unsigned vmargin = margin.top+margin.bottom+line_height-line_spacing; - unsigned n_lines = min(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(lines.size(), max(free_height/line_spacing, 1U)); if(fit_height) *fit_height = line_height+(n_lines-1)*line_spacing;