From 5ba09fdde8aa29bf5deab65dc7424df6d3557527 Mon Sep 17 00:00:00 2001 From: Kwangseob Jeong Date: Thu, 5 Dec 2024 13:49:57 +0900 Subject: [PATCH] Fix max init value in functions to 1 (#36686) - Changed the initial value of max to 1 within the function. - If max is not updated during the for loop, it returns -1, which can cause an INTEGER_OVERFLOW - By initializing max to 1, it ensures that if max is updated during the loop, the updated value is used. - If no value is updated, it performs the -1 operation and updates to 0. --- src/lib/dnssd/TxtFields.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dnssd/TxtFields.h b/src/lib/dnssd/TxtFields.h index 5546493624119d..49d10bf39aa1ae 100644 --- a/src/lib/dnssd/TxtFields.h +++ b/src/lib/dnssd/TxtFields.h @@ -121,7 +121,7 @@ uint8_t GetCommissionerPasscode(const ByteSpan & value); constexpr size_t MaxKeyLen(TxtKeyUse use) { - size_t max = 0; + size_t max = 1; for (auto & info : Internal::txtFieldInfo) { if (use == info.use) @@ -147,7 +147,7 @@ constexpr size_t TotalKeyLen(TxtKeyUse use) constexpr size_t MaxValueLen(TxtKeyUse use) { - size_t max = 0; + size_t max = 1; for (auto & info : Internal::txtFieldInfo) { if (use == info.use)