Skip to content

Commit 9a014b9

Browse files
committed
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.
1 parent a3a443a commit 9a014b9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib/dnssd/TxtFields.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ uint8_t GetCommissionerPasscode(const ByteSpan & value);
121121

122122
constexpr size_t MaxKeyLen(TxtKeyUse use)
123123
{
124-
size_t max = 0;
124+
size_t max = 1;
125125
for (auto & info : Internal::txtFieldInfo)
126126
{
127127
if (use == info.use)
@@ -147,7 +147,7 @@ constexpr size_t TotalKeyLen(TxtKeyUse use)
147147

148148
constexpr size_t MaxValueLen(TxtKeyUse use)
149149
{
150-
size_t max = 0;
150+
size_t max = 1;
151151
for (auto & info : Internal::txtFieldInfo)
152152
{
153153
if (use == info.use)

0 commit comments

Comments
 (0)