From c8ecd0eb22d5f2578439b8fed4db8879a91cb026 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 1 Mar 2025 13:38:00 -0300 Subject: [PATCH] QMessageLogger: reject negative values for QT_FATAL_xxx Amends ceb859bf036dfdd1c54eec403006eac62a0d09b8 We'd accept negative values and keep counting downwards, reaching 0 again only after a full underflow[*]. Effectively, this meant that a negative value was the same as zero, so this makes the behavior explicit. The commit introducing checked_var_value() said in its changelog: For compatibility reasons with previous versions, if the variable is set to any non-empty and non-numeric value different from 0, Qt will understand as "stop on first warning". Negative values are not "non-empty and non-numeric", so this commit chooses to make the current behavior explicit. [*] atomic under- and overflows are defined behavior, but only if the atomic operation is the one producing it. The current code is doing the subtraction by itself in the call to testAndSetRelaxed(), so underflows are still UB. If/when this is replaced by atomicMutate, that might change (and note to self when implementing that!). Pick-to: 6.9 6.8 Change-Id: I594ed31f1cc7fc04ea98c6e86bdcaa3a4aa59114 Reviewed-by: Ahmad Samir Reviewed-by: Ivan Solovev Reviewed-by: Marc Mutz --- src/corelib/global/qlogging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 2adf306650a..b26b5cc1321 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -146,7 +146,7 @@ static int checked_var_value(const char *varname) bool ok; int value = str.toInt(&ok, 0); - return ok ? value : 1; + return (ok && value >= 0) ? value : 1; } static bool is_fatal_count_down(QAtomicInt &n)