summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qipaddress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qipaddress.cpp')
-rw-r--r--src/corelib/io/qipaddress.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index eeb3d79b06..c2b274f8b5 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -22,9 +22,9 @@ static QString number(quint8 val)
typedef QVarLengthArray<char, 64> Buffer;
static const QChar *checkedToAscii(Buffer &buffer, const QChar *begin, const QChar *end)
{
- const ushort *const ubegin = reinterpret_cast<const ushort *>(begin);
- const ushort *const uend = reinterpret_cast<const ushort *>(end);
- const ushort *src = ubegin;
+ const auto *const ubegin = reinterpret_cast<const char16_t *>(begin);
+ const auto *const uend = reinterpret_cast<const char16_t *>(end);
+ auto *src = ubegin;
buffer.resize(uend - ubegin + 1);
char *dst = buffer.data();
@@ -60,14 +60,12 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL
ptr[1] != '.' && ptr[1] != '\0')
return false;
- const char *endptr;
- bool ok;
- quint64 ll = qstrntoull(ptr, stop - ptr, &endptr, 0, &ok);
- quint32 x = ll;
- if (!ok || endptr == ptr || ll != x)
+ auto [ll, used] = qstrntoull(ptr, stop - ptr, 0);
+ const quint32 x = quint32(ll);
+ if (used <= 0 || ll != x)
return false;
- if (*endptr == '.' || dotCount == 3) {
+ if (ptr[used] == '.' || dotCount == 3) {
if (x & ~0xff)
return false;
address <<= 8;
@@ -82,13 +80,13 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL
}
address |= x;
- if (dotCount == 3 || *endptr == '\0')
- return *endptr == '\0';
- if (*endptr != '.')
+ if (dotCount == 3 || ptr[used] == '\0')
+ return ptr[used] == '\0';
+ if (ptr[used] != '.')
return false;
++dotCount;
- ptr = endptr + 1;
+ ptr += used + 1;
}
return false;
}
@@ -176,18 +174,16 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end
continue;
}
- const char *endptr;
- bool ok;
- quint64 ll = qstrntoull(ptr, stop - ptr, &endptr, 16, &ok);
+ auto [ll, used] = qstrntoull(ptr, stop - ptr, 16);
quint16 x = ll;
// Reject malformed fields:
// - failed to parse
// - too many hex digits
- if (!ok || endptr > ptr + 4)
+ if (used <= 0 || used > 4)
return begin + (ptr - buffer.data());
- if (*endptr == '.') {
+ if (ptr[used] == '.') {
// this could be an IPv4 address
// it's only valid in the last element
if (pos != 12)
@@ -207,11 +203,11 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end
address[pos++] = x >> 8;
address[pos++] = x & 0xff;
- if (*endptr == '\0')
+ if (ptr[used] == '\0')
break;
- if (*endptr != ':')
- return begin + (endptr - buffer.data());
- ptr = endptr + 1;
+ if (ptr[used] != ':')
+ return begin + (used + ptr - buffer.data());
+ ptr += used + 1;
}
return pos == 16 ? nullptr : end;
}