Skip to content

Commit cce82b1

Browse files
committed
nsapi - Fixed unaligned writes from <word-sized scanf calls
1 parent 281a0e2 commit cce82b1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

features/netsocket/SocketAddress.cpp

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

6868
for (; count < NSAPI_IPv4_BYTES; count++) {
69-
int scanned = sscanf(&addr[i], "%hhu", &bytes[count]);
69+
unsigned char b;
70+
int scanned = sscanf(&addr[i], "%hhu", &b);
7071
if (scanned < 1) {
7172
return;
7273
}
7374

75+
bytes[count] = b;
76+
7477
for (; addr[i] != '.'; i++) {
7578
if (!addr[i]) {
7679
return;
@@ -86,11 +89,14 @@ static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) {
8689
int i = 0;
8790

8891
for (; count < NSAPI_IPv6_BYTES/2; count++) {
89-
int scanned = sscanf(&chunk[i], "%hx", &shorts[count]);
92+
unsigned short s;
93+
int scanned = sscanf(&chunk[i], "%hx", &s);
9094
if (scanned < 1) {
9195
return count;
9296
}
9397

98+
shorts[count] = s;
99+
94100
for (; chunk[i] != ':'; i++) {
95101
if (!chunk[i]) {
96102
return count+1;

0 commit comments

Comments
 (0)