From 31bee50102d92ad41864d1fd6f05b9ce85e088b2 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 3 Dec 2018 16:59:38 +0100 Subject: [PATCH] IPAddress: allow misaligned source in constructor (#5421) --- cores/esp8266/IPAddress.cpp | 10 +++++++++- cores/esp8266/IPAddress.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/IPAddress.cpp b/cores/esp8266/IPAddress.cpp index bf6a45b87..d121ba6e5 100644 --- a/cores/esp8266/IPAddress.cpp +++ b/cores/esp8266/IPAddress.cpp @@ -22,6 +22,11 @@ #include #include +IPAddress::IPAddress(const IPAddress& from) +{ + ip_addr_copy(_ip, from._ip); +} + IPAddress::IPAddress() { _ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address } @@ -45,7 +50,10 @@ void IPAddress::ctor32(uint32_t address) { IPAddress::IPAddress(const uint8_t *address) { setV4(); - v4() = *reinterpret_cast(address); + (*this)[0] = address[0]; + (*this)[1] = address[1]; + (*this)[2] = address[2]; + (*this)[3] = address[3]; } bool IPAddress::fromString(const char *address) { diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index f457127de..7d2a95189 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -72,6 +72,7 @@ class IPAddress: public Printable { public: // Constructors IPAddress(); + IPAddress(const IPAddress& from); IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); IPAddress(uint32_t address) { ctor32(address); } IPAddress(u32_t address) { ctor32(address); }