Skip to content

Commit

Permalink
Fix max init value in functions to 1 (#36686)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
myddpp authored Dec 5, 2024
1 parent ca772d7 commit 5ba09fd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/dnssd/TxtFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 5ba09fd

Please sign in to comment.