From 43e4603c5576970f746f46311825f19cffc66e18 Mon Sep 17 00:00:00 2001 From: Andre Rummler Date: Fri, 7 Aug 2026 07:59:39 +0200 Subject: [PATCH] Fixing minimum width calculation for title block which could lead to division by zero and subsequent program crash if opening a template with only relative sized columns. --- sources/titleblocktemplate.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 782b3b532..63a3631a6 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -26,6 +26,7 @@ #include #include +#include /** @brief TitleBlockTemplate::TitleBlockTemplate Constructor @@ -973,14 +974,20 @@ int TitleBlockTemplate::minimumWidth() // => (1 - (sum(REL)/100))TOT >= sum(ABS) // => TOT >= sum(ABS) / (1 - (sum(REL)/100)) // => TOT >= sum(ABS) / ((100 - sum(REL))/100)) - return( - qRound( - columnTypeTotal(QET::Absolute) - / - ((100.0 - columnTypeTotal(QET::RelativeToTotalLength)) - / 100.0) - ) - ); + int abs_total = columnTypeTotal(QET::Absolute); + qreal denominator = (100.0 - columnTypeTotal(QET::RelativeToTotalLength)) / 100.0; + + if (denominator <= 0.0) { + // The relative-to-total-length columns alone already consume + // 100% (or more) of the available width, so the formula above + // would divide by zero (or go negative). If there are no + // absolute-width columns, there is no meaningful minimum width + // to enforce; if there are, the template is asking for more + // than 100% of its own width, which cannot be satisfied. + return abs_total > 0 ? std::numeric_limits::max() : 0; + } + + return(qRound(abs_total / denominator)); } /**