window_layouter: calculate weighted dimension in double

The change prevents integer overflows with reasonable large values.

Thanks Peter for reporting.
This commit is contained in:
Christian Helmuth
2024-04-29 16:08:56 +02:00
parent fc27469b97
commit 3a0ded3bdd

View File

@ -76,7 +76,7 @@ class Window_layouter::Target_list
} }
/* amount of pixels we can use for weighed columns */ /* amount of pixels we can use for weighed columns */
unsigned const weigthed_avail = avail_px - preserved_pixels; unsigned const weighted_avail = avail_px - preserved_pixels;
/* /*
* Calculate positions * Calculate positions
@ -91,9 +91,9 @@ class Window_layouter::Target_list
if (px) if (px)
return px; return px;
unsigned const weight = weight_attr_value(child); double const weight = weight_attr_value(child);
if (weight && total_weight) if (weight && total_weight)
return (((weight << 16)*weigthed_avail)/total_weight) >> 16; return (unsigned) (weight/total_weight*weighted_avail);
return 0U; return 0U;
}; };
@ -103,12 +103,12 @@ class Window_layouter::Target_list
if (weighted) if (weighted)
count_weighted++; count_weighted++;
/* true if target is the last weigthed column or row */ /* true if target is the last weighted column or row */
bool const last_weighted = weighted bool const last_weighted = weighted
&& (count_weighted == num_weighted); && (count_weighted == num_weighted);
unsigned const px_size = last_weighted unsigned const px_size = last_weighted
? (weigthed_avail - used_weighted) ? (weighted_avail - used_weighted)
: calc_px_size(); : calc_px_size();
if (weighted) if (weighted)