From: Kevin Day Date: Tue, 6 Aug 2024 01:48:57 +0000 (-0500) Subject: Regression: IPv6 detection is failing after isdigit() and similar changes. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=aa77562f93057d3488333cde46e45bb5d3992f80;p=fll Regression: IPv6 detection is failing after isdigit() and similar changes. The commit 50788517d37ece42f32f6906078d2d59330ec3c9 missed a not operator for the IPv6 address. The unit tests revealed the problem. This adds the missing exclamation character '!'. I also overlooked some cases where I could perform the same optimization used for the referenced commit in some places. Also use the literal ASCII characters rather than the strings. The ASCII codes are required and expected and substitution of the characters for the algorithm do not make sense here. These are characters rather than strings. --- diff --git a/level_0/f_network/c/network.c b/level_0/f_network/c/network.c index 7471e8c..96c8231 100644 --- a/level_0/f_network/c/network.c +++ b/level_0/f_network/c/network.c @@ -138,7 +138,7 @@ extern "C" { if (!address.string[i]) continue; if ((uint16_t) (address.string[i] - 'a') < 6 || (uint16_t) (address.string[i] - 'A') < 6 || (uint16_t) (address.string[i] - '0') < 10) { - if (address.string[i] < f_string_ascii_0_s.string[0] || address.string[i] > f_string_ascii_9_s.string[0]) { + if ((uint16_t) (address.string[i] - '0') > 9) { flag = 0x1; } @@ -151,7 +151,7 @@ extern "C" { continue; } - if (address.string[i] == f_string_ascii_period_s.string[0]) { + if (address.string[i] == '.') { // An IPv4 looking address with a hexidecimal letter. if (flag & 0x1) { @@ -163,7 +163,7 @@ extern "C" { break; } - if (address.string[i] == f_string_ascii_colon_s.string[0]) { + if (address.string[i] == ':') { flag = 0x1; count = 0; @@ -175,7 +175,7 @@ extern "C" { break; } - if (address.string[i] == f_string_ascii_bracket_open_s.string[0]) { + if (address.string[i] == '[') { if (flag) { state->status = F_false; @@ -247,10 +247,10 @@ extern "C" { if (++count > 4) return; if (flag & 0x4) { - if (address.string[i] < f_string_ascii_0_s.string[0] || address.string[i] > f_string_ascii_9_s.string[0] || count > 3) return; + if ((uint16_t) (address.string[i] - '0') > 9 || count > 3) return; } } - else if (address.string[i] == f_string_ascii_colon_s.string[0]) { + else if (address.string[i] == ':') { if (flag & 0x4) return; at.start_2 = i + 1; @@ -271,7 +271,7 @@ extern "C" { if (at.start_2 == address.used) return; - if (address.string[at.start_2] == f_string_ascii_colon_s.string[0]) { + if (address.string[at.start_2] == ':') { if (flag & 0x8) return; flag |= 0x8; @@ -293,7 +293,7 @@ extern "C" { } // Colons must be followed by a hexidecimal digit. - if (!((uint16_t) (address.string[at.start_2] - 'a') < 6 || (uint16_t) (address.string[at.start_2] - 'A') < 6 || (uint16_t) (address.string[at.start_2] - '0') < 10)) return; + if ((uint16_t) (address.string[at.start_2] - 'a') > 5 && (uint16_t) (address.string[at.start_2] - 'A') > 5 && (uint16_t) (address.string[at.start_2] - '0') > 9) return; // When double-colons lead, then set the start position at this digit. if (!count && !set) { @@ -324,12 +324,12 @@ extern "C" { count = 0; at.start_2 = 1; } - else if (address.string[i] == f_string_ascii_slash_forward_s.string[0]) { + else if (address.string[i] == '/') { if (flag & 0x4) return; flag |= 0x4; } - else if (address.string[i] == f_string_ascii_bracket_close_s.string[0]) { + else if (address.string[i] == ']') { if (!(flag & 0x2)) return; at.stop_1 = i - 1; @@ -347,7 +347,7 @@ extern "C" { } // for if (at.start_2 < address.used) { - if (address.string[at.start_2] == f_string_ascii_colon_s.string[0]) { + if (address.string[at.start_2] == ':') { // Skip past NULL characters. while (++at.start_2 < address.used && !address.string[at.start_2]) { @@ -373,7 +373,7 @@ extern "C" { } if (!address.string[at.stop_2]) continue; - if ((uint16_t) (address.string[at.stop_2] - '0') < 10) return; + if ((uint16_t) (address.string[at.stop_2] - '0') > 9) return; } // for // The double colon either must exist when set is smaller than 7 or the double colon must not exist at all. @@ -473,12 +473,12 @@ extern "C" { if (++count > 3) return; } } - else if (address.string[i] == f_string_ascii_period_s.string[0]) { + else if (address.string[i] == '.') { if ((flag & 0x6) || !count || ++set > 3) return; count = 0; } - else if (address.string[i] == f_string_ascii_colon_s.string[0]) { + else if (address.string[i] == ':') { if (set != 3 || (flag & 0x2)) return; // The address ends before the colon. @@ -506,7 +506,7 @@ extern "C" { // Save the position that might represent the start of the port number. at.start_2 = i + 1; } - else if (address.string[i] == f_string_ascii_slash_forward_s.string[0]) { + else if (address.string[i] == '/') { if ((flag & 0x4) || set != 3) return; flag |= 0x4;