From 9a014b9f600a9ced38dc0beac0e4b096f2f4201c Mon Sep 17 00:00:00 2001
From: Kwangseob Jeong <myddpp@naver.com>
Date: Mon, 2 Dec 2024 09:04:53 +0900
Subject: [PATCH] Fix max init value in functions to 1

- 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)