Skip to content

Commit 31bee50

Browse files
authored
IPAddress: allow misaligned source in constructor (#5421)
1 parent ca3678f commit 31bee50

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cores/esp8266/IPAddress.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include <Print.h>
2323
#include <StreamString.h>
2424

25+
IPAddress::IPAddress(const IPAddress& from)
26+
{
27+
ip_addr_copy(_ip, from._ip);
28+
}
29+
2530
IPAddress::IPAddress() {
2631
_ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address
2732
}
@@ -45,7 +50,10 @@ void IPAddress::ctor32(uint32_t address) {
4550

4651
IPAddress::IPAddress(const uint8_t *address) {
4752
setV4();
48-
v4() = *reinterpret_cast<const uint32_t*>(address);
53+
(*this)[0] = address[0];
54+
(*this)[1] = address[1];
55+
(*this)[2] = address[2];
56+
(*this)[3] = address[3];
4957
}
5058

5159
bool IPAddress::fromString(const char *address) {

cores/esp8266/IPAddress.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class IPAddress: public Printable {
7272
public:
7373
// Constructors
7474
IPAddress();
75+
IPAddress(const IPAddress& from);
7576
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
7677
IPAddress(uint32_t address) { ctor32(address); }
7778
IPAddress(u32_t address) { ctor32(address); }

0 commit comments

Comments
 (0)