From abd25f9bb3197f1c934120c500b51b07e9890a86 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 20 Apr 2016 03:22:31 -0500 Subject: [PATCH] Added workaround for bug in newlib sscanf https://bugs.launchpad.net/gcc-arm-embedded/+bug/1399224 --- SocketAddress.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SocketAddress.cpp b/SocketAddress.cpp index f238c883d8..933f851731 100644 --- a/SocketAddress.cpp +++ b/SocketAddress.cpp @@ -56,7 +56,23 @@ static bool ipv6_is_valid(const char *addr) static void ipv4_from_address(uint8_t *bytes, const char *addr) { - sscanf(addr, "%hhu.%hhu.%hhu.%hhu", &bytes[0], &bytes[1], &bytes[2], &bytes[3]); + int count = 0; + int i = 0; + + for (; count < NSAPI_IPv4_BYTES; count++) { + int scanned = sscanf(&addr[i], "%hhu", &bytes[count]); + if (scanned < 1) { + return; + } + + for (; addr[i] != '.'; i++) { + if (!addr[i]) { + return; + } + } + + i++; + } } static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) {