Skip to content

Commit e2b5b52

Browse files
committed
use IPV4_MAX_DOT_NUM
1 parent ec35143 commit e2b5b52

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

libc/src/arpa/inet/inet_aton.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
namespace LIBC_NAMESPACE_DECL {
1515

1616
LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
17-
unsigned long parts[4] = {0};
17+
constexpr int IPV4_MAX_DOT_NUM = 3;
18+
unsigned long parts[IPV4_MAX_DOT_NUM + 1] = {0};
1819
int dot_num = 0;
1920

20-
for (; dot_num < 4; ++dot_num) {
21+
for (; dot_num <= IPV4_MAX_DOT_NUM; ++dot_num) {
2122
auto result = internal::strtointeger<unsigned long>(cp, 0);
2223
parts[dot_num] = result;
2324

@@ -32,7 +33,7 @@ LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
3233
cp += (result.parsed_len + 1);
3334
}
3435

35-
if (dot_num > 3)
36+
if (dot_num > IPV4_MAX_DOT_NUM)
3637
return 0;
3738

3839
unsigned long result = 0;
@@ -41,7 +42,7 @@ LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
4142
i == dot_num ? (0xffffffffUL >> (8 * dot_num)) : 0xffUL;
4243
if (parts[i] > max_part)
4344
return 0;
44-
int shift = i == dot_num ? 0 : 8 * (3 - i);
45+
int shift = i == dot_num ? 0 : 8 * (IPV4_MAX_DOT_NUM - i);
4546
result |= parts[i] << shift;
4647
}
4748

0 commit comments

Comments
 (0)