Skip to content

Commit f5385e7

Browse files
authored
Merge pull request #6524 from forGGe/fix_address_parsing_
Fix IPv4 address parsing due to not-so-portable scanf modifier
2 parents f331ac3 + bd47110 commit f5385e7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

features/netsocket/SocketAddress.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ static void ipv4_from_address(uint8_t *bytes, const char *addr)
6666
int i = 0;
6767

6868
for (; count < NSAPI_IPv4_BYTES; count++) {
69-
unsigned char b;
70-
int scanned = sscanf(&addr[i], "%hhu", &b);
69+
unsigned d;
70+
// Not using %hh, since it might be missing in newlib-based toolchains.
71+
// See also: https://git.io/vxiw5
72+
int scanned = sscanf(&addr[i], "%u", &d);
7173
if (scanned < 1) {
7274
return;
7375
}
7476

75-
bytes[count] = b;
77+
bytes[count] = static_cast<uint8_t>(d);
7678

7779
for (; addr[i] != '.'; i++) {
7880
if (!addr[i]) {

0 commit comments

Comments
 (0)