Repository: dotnet/runtime
File: src/libraries/Common/src/System/Net/IPv4AddressHelper.Common.cs (C#)

Code before:
            {
                int ch = ToUShort(name[start]);

                if (allowIPv6)
                {
                    // For an IPv4 address nested inside an IPv6 address, the terminator is either the IPv6 address terminator (']'), prefix ('/') or ScopeId ('%')
                    if (ch == ']' || ch == '/' || ch == '%')
                    {
                        break;
                    }
                }
                else if (ch == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
                {
                    // For a normal IPv4 address, the terminator is the prefix ('/' or its counterpart, '\'). If notImplicitFile is set, the terminator
                    // is one of the characters which signify the start of the rest of the URI - the port number (':'), query string ('?') or fragment ('#')

                    break;
                }

                // An explicit cast to an unsigned integer forces character values preceding '0' to underflow, eliminating one comparison below.
                uint parsedCharacter = (uint)(ch - '0');

                if (parsedCharacter < IPv4AddressHelper.Decimal)
                {
                    if (!haveNumber && parsedCharacter == 0 &&
                        (uint)(start + 1) < (uint)name.Length && char.IsBetween((char)ToUShort(name[start + 1]), '0', '9'))
                    {
                        // Octal is not allowed in canonical format.
                        return false;
                    }

                    haveNumber = true;
                    number = number * IPv4AddressHelper.Decimal + parsedCharacter;
                    if (number > byte.MaxValue)
                    {
                        return false;
                    }
                }
                else if (ch == '.')
                {
                    // If the current character is not an integer, it may be the IPv4 component separator ('.')

                    if (!haveNumber)
                    {
                        return false;
                    }

                    ++dots;
                    haveNumber = false;
                    number = 0;
                }

Review comment (suggestion):
```suggestion
                        (uint)(start + 1) < (uint)name.Length && char.IsAsciiDigit((char)ToUShort(name[start + 1])))
```

Code after:
            {
                int ch = ToUShort(name[start]);

                if (allowIPv6)
                {
                    // For an IPv4 address nested inside an IPv6 address, the terminator is either the IPv6 address terminator (']'), prefix ('/') or ScopeId ('%')
                    if (ch == ']' || ch == '/' || ch == '%')
                    {
                        break;
                    }
                }
                else if (ch == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
                {
                    // For a normal IPv4 address, the terminator is the prefix ('/' or its counterpart, '\'). If notImplicitFile is set, the terminator
                    // is one of the characters which signify the start of the rest of the URI - the port number (':'), query string ('?') or fragment ('#')

                    break;
                }

                // An explicit cast to an unsigned integer forces character values preceding '0' to underflow, eliminating one comparison below.
                uint parsedCharacter = (uint)(ch - '0');

                if (parsedCharacter < IPv4AddressHelper.Decimal)
                {
                    if (!haveNumber && parsedCharacter == 0 &&
                        (uint)(start + 1) < (uint)name.Length && char.IsAsciiDigit((char)ToUShort(name[start + 1])))
                    {
                        // Octal is not allowed in canonical format.
                        return false;
                    }

                    haveNumber = true;
                    number = number * IPv4AddressHelper.Decimal + parsedCharacter;
                    if (number > byte.MaxValue)
                    {
                        return false;
                    }
                }
                else if (ch == '.')
                {
                    // If the current character is not an integer, it may be the IPv4 component separator ('.')

                    if (!haveNumber)
                    {
                        return false;
                    }

                    ++dots;
                    haveNumber = false;
                    number = 0;
                }