This commit is contained in:
maynk27 2024-06-19 00:40:16 +05:30
parent 40d01a1b7f
commit 1ae169a5da
2 changed files with 5 additions and 4 deletions

View File

@ -88,7 +88,7 @@ inline bool parseIPv4(T * &src, EOFfunction eof, unsigned char * dst, int32_t fi
/// returns pointer to the right after parsed sequence or null on failed parsing
inline const char * parseIPv4(const char * src, const char * end, unsigned char * dst)
{
if (parseIPv4(src, [&src, end](){ return src == end; }, dst))
if (parseIPv4(src, [&src, end](){ return src == end || *src == '\0'; }, dst))
return src;
return nullptr;
}
@ -96,7 +96,8 @@ inline const char * parseIPv4(const char * src, const char * end, unsigned char
/// returns true if whole buffer was parsed successfully
inline bool parseIPv4whole(const char * src, const char * end, unsigned char * dst)
{
return parseIPv4(src, end, dst) == reinterpret_cast<const char *>(dst);
const char * parsed = parseIPv4(src, end, dst);
return parsed-end == 0;
}
/// returns pointer to the right after parsed sequence or null on failed parsing

View File

@ -31,8 +31,8 @@ ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
127.0.0.1 is ipv4 string: 1
8.8.8.8 is ipv4 string: 1
hello is ipv4 string: 0
192.168.1.1\0000 is ipv4 string: 0
192.168.1.1\00dc is ipv4 string: 0
192.168.1.1\0000 is ipv4 string: 0
192.168.1.1\00dc is ipv4 string: 0
0:0:0:0:0:0:0:0 is ipv4 string: 0
0000:0000:0000:0000:0000:FFFF:C1FC:110A is ipv4 string: 0
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF is ipv4 string: 0