Skip to content

Commit 9027b33

Browse files
myddppks80jeong
authored andcommitted
Add return value check for avoid interger overflow
To avoid overflowed constant(INTEGER_OVERFLOW) occurrence, minus operation is performed only when the value is greater than 0
1 parent e402b96 commit 9027b33

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
@@ -130,7 +130,7 @@ constexpr size_t MaxKeyLen(TxtKeyUse use)
130130
}
131131
}
132132
// minus 1 because sizeof includes the null terminator.
133-
return max - 1;
133+
return max > 0 ? max - 1 : 0;
134134
}
135135
constexpr size_t TotalKeyLen(TxtKeyUse use)
136136
{
@@ -156,7 +156,7 @@ constexpr size_t MaxValueLen(TxtKeyUse use)
156156
}
157157
}
158158
// minus 1 because sizeof includes the null terminator.
159-
return max - 1;
159+
return max > 0 ? max - 1 : 0;
160160
}
161161
constexpr size_t TotalValueLen(TxtKeyUse use)
162162
{

0 commit comments

Comments
 (0)