[num-utils] add SetToUintMax() to prevent type-mismatch bugs (#11969)

Introduces a new template helper function `SetToUintMax()` in
`common/num_utils.hpp`. This function sets a given unsigned integer
variable to its maximum possible value.

The `SetToUintMax()` function infers the type of the variable,
ensuring that the correct `NumericLimits<...>::kMax` is used. This
prevents potential bugs where a variable could be assigned the max
value of a wrong `uint` type.

Existing code across different modules is updated to use this new
helper function, improving code safety and robustness.
This commit is contained in:
Abtin Keshavarzian
2025-09-30 16:59:39 -07:00
committed by GitHub
parent 05c0009046
commit c8ccc84b3b
8 changed files with 30 additions and 10 deletions
+1 -1
View File
@@ -3510,7 +3510,7 @@ Error Mle::AddrSolicitInfo::ParseFrom(const Coap::Message &aMessage)
case kErrorNone:
break;
case kErrorNotFound:
mXtalAccuracy = NumericLimits<uint16_t>::kMax;
SetToUintMax(mXtalAccuracy);
break;
default:
ExitNow(error = kErrorParse);