Skip to content

IPAddress::operator= needs 32-bit aligned pointer #8817

Closed
@TD-er

Description

@TD-er

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12|ESP-01|ESP-07|ESP8285 device|other]
  • Core Version: [Current master / 2.7.4]
  • Development Env: [Platformio]
  • Operating System: [Windows|Ubuntu]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [qio|dio|other]
  • Flash Size: [4MB/1MB]
  • lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz|160MHz]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200|other] (serial upload only)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions