mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 01:47:47 +00:00
[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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user