Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IPv4 address parsing due to not-so-portable scanf modifier #6524

Merged
merged 1 commit into from Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions features/netsocket/SocketAddress.cpp
Expand Up @@ -66,13 +66,15 @@ static void ipv4_from_address(uint8_t *bytes, const char *addr)
int i = 0;

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

bytes[count] = b;
bytes[count] = static_cast<uint8_t>(d);

for (; addr[i] != '.'; i++) {
if (!addr[i]) {
Expand Down