Skip to content

Commit abd25f9

Browse files
committed
Added workaround for bug in newlib sscanf
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1399224
1 parent cd4a521 commit abd25f9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

SocketAddress.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,23 @@ static bool ipv6_is_valid(const char *addr)
5656

5757
static void ipv4_from_address(uint8_t *bytes, const char *addr)
5858
{
59-
sscanf(addr, "%hhu.%hhu.%hhu.%hhu", &bytes[0], &bytes[1], &bytes[2], &bytes[3]);
59+
int count = 0;
60+
int i = 0;
61+
62+
for (; count < NSAPI_IPv4_BYTES; count++) {
63+
int scanned = sscanf(&addr[i], "%hhu", &bytes[count]);
64+
if (scanned < 1) {
65+
return;
66+
}
67+
68+
for (; addr[i] != '.'; i++) {
69+
if (!addr[i]) {
70+
return;
71+
}
72+
}
73+
74+
i++;
75+
}
6076
}
6177

6278
static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) {

0 commit comments

Comments
 (0)