| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 34d70ce commit 360a3f3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ | |||
| 6 | 6 | #include "util-inl.h" | |
| 7 | 7 | ||
| 8 | 8 | #include <algorithm> | |
| 9 | - #include <cmath> | ||
| 10 | 9 | #include <cstdio> | |
| 11 | 10 | #include <numeric> | |
| 12 | 11 | #include <string> | |
@@ -477,18 +476,18 @@ void URLHost::ParseIPv4Host(const char* input, size_t length) { | |||
| 477 | 476 | const char* pointer = input; | |
| 478 | 477 | const char* mark = input; | |
| 479 | 478 | const char* end = pointer + length; | |
| 480 | - int parts = 0; | ||
| 479 | + unsigned int parts = 0; | ||
| 481 | 480 | uint32_t val = 0; | |
| 482 | 481 | uint64_t numbers[4]; | |
| 483 | - int tooBigNumbers = 0; | ||
| 482 | + unsigned int tooBigNumbers = 0; | ||
| 484 | 483 | if (length == 0) | |
| 485 | 484 | return; | |
| 486 | 485 | ||
| 487 | 486 | while (pointer <= end) { | |
| 488 | 487 | const char ch = pointer < end ? pointer[0] : kEOL; | |
| 489 | 488 | int64_t remaining = end - pointer - 1; | |
| 490 | 489 | if (ch == '.' || ch == kEOL) { | |
| 491 | - if (++parts > static_cast<int>(arraysize(numbers))) return; | ||
| 490 | + if (++parts > arraysize(numbers)) return; | ||
| 492 | 491 | if (pointer == mark) | |
| 493 | 492 | return; | |
| 494 | 493 | int64_t n = ParseIPv4Number(mark, pointer); | |
@@ -510,18 +509,15 @@ void URLHost::ParseIPv4Host(const char* input, size_t length) { | |||
| 510 | 509 | // If any but the last item in numbers is greater than 255, return failure. | |
| 511 | 510 | // If the last item in numbers is greater than or equal to | |
| 512 | 511 | // 256^(5 - the number of items in numbers), return failure. | |
| 513 | - if (tooBigNumbers > 1 || | ||
| 514 | - (tooBigNumbers == 1 && numbers[parts - 1] <= 255) || | ||
| 515 | - numbers[parts - 1] >= pow(256, static_cast<double>(5 - parts))) { | ||
| 512 | + if (tooBigNumbers > 1 || (tooBigNumbers == 1 && numbers[parts - 1] <= 255) || | ||
| 513 | + numbers[parts - 1] >= UINT64_C(1) << (8 * (5 - parts))) { | ||
| 516 | 514 | return; | |
| 517 | 515 | } | |
| 518 | 516 | ||
| 519 | 517 | type_ = HostType::H_IPV4; | |
| 520 | 518 | val = static_cast<uint32_t>(numbers[parts - 1]); | |
| 521 | - for (int n = 0; n < parts - 1; n++) { | ||
| 522 | - double b = 3 - n; | ||
| 523 | - val += | ||
| 524 | - static_cast<uint32_t>(numbers[n]) * static_cast<uint32_t>(pow(256, b)); | ||
| 519 | + for (unsigned int n = 0; n < parts - 1; n++) { | ||
| 520 | + val += static_cast<uint32_t>(numbers[n]) << (8 * (3 - n)); | ||
| 525 | 521 | } | |
| 526 | 522 | ||
| 527 | 523 | value_.ipv4 = val; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments