IPAddress::operator= needs 32-bit aligned pointer · Issue #8817 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

Settings in IDE

Problem Description

LoadStoreAlignmentCause: Load or store to an unaligned address
  epc1=0x402a1358 in IPAddress::operator=(unsigned char const*) at ??:?
en deze stacktrace:
0x4029280d in String::operator=(char const*) at ??:?
0x401012bb in umm_free_core at umm_malloc.cpp:?
0x401015a2 in malloc at ??:?
0x402d1866 in wifi_get_opmode at ??:?
0x402a2568 in spiffs_cache_page_get_by_fd at ??:?
0x402a2568 in spiffs_cache_page_get_by_fd at ??:?
0x402a2568 in spiffs_cache_page_get_by_fd at ??:?
0x402a2568 in spiffs_cache_page_get_by_fd at ??:?
0x4024821f in setConnectionSpeed() at ??:?
0x40248dc2 in prepareWiFi() at ??:?
0x40241468 in WiFiEventData_t::markWiFiBegin() at ??:?
0x40248f29 in AttemptWiFiConnect() at ??:?
0x40205e24 in ESP8266WiFiSTAClass::status() at ??:?
0x40248084 in wifiAPmodeActivelyUsed() at ??:?
0x4024909c in WiFiConnectRelaxed() at ??:?
0x40245ce9 in NetworkConnectRelaxed() at ??:?
0x4024bf23 in ESPEasy_setup() at ??:?
0x40215084 in setup at ??:?
0x40293ddb in loop_wrapper() at core_esp8266_main.cpp:?
0x40100469 in cont_wrapper at ??:?

See the assignment operator and other functions where the const uint8_t* is cast to an const uint32_t*

IPAddress& IPAddress::operator=(const uint8_t *address) {
setV4();
v4() = *reinterpret_cast<const uint32_t*>(address);
return *this;
}
bool IPAddress::operator==(const uint8_t* addr) const {
return isV4() && v4() == *reinterpret_cast<const uint32_t*>(addr);
}

The call is simply like this:

const IPAddress ip = Settings.IP; const IPAddress gw = Settings.Gateway; const IPAddress subnet = Settings.Subnet; const IPAddress dns = Settings.DNS;

Where all these are part of a larger struct, which begins like this:

unsigned long PID = 0; int Version = 0; int16_t Build = 0; uint8_t IP[4] = {0}; uint8_t Gateway[4] = {0}; uint8_t Subnet[4] = {0}; uint8_t DNS[4] = {0};

As can be seen, these are indeed not 32-bit aligned.

I think the build toolchain may recently have been updated, as this struct and the code that's now failing has not been changed for at least 4 years.

The same code in IPAddress has not been changed for a while as the current master branch has the same code for these functions as the 2.7.4 we're using.