Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wled00/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool initEthernet()
}

// https://github.com/wled/WLED/issues/5247
if (multiWiFi[0].staticIP != (uint32_t)0x00000000 && multiWiFi[0].staticGW != (uint32_t)0x00000000) {
if (multiWiFi.size() && multiWiFi[0].staticIP != IPAddress() && multiWiFi[0].staticGW != IPAddress()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that the addition of if (multiWiFi.size() is the actual fix.

@coderabbitai how is IPAddress() defined? Is it the same as 0.0.0.0 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== IPAddress declarations/uses ==='
rg -n -C 3 'class IPAddress|IPAddress::IPAddress|IPAddress\(\)' \
  -g '*.{h,hpp,cpp,ino}' .

printf '%s\n' '=== Arduino-ESP32 framework version references ==='
rg -n -C 2 'arduino-esp32|ESP_ARDUINO_VERSION|platform.*espressif32' \
  -g 'platformio.ini' -g 'platformio*.ini' -g 'package.json' -g '*.json' -g '*.md' .

Length of output: 14902


@softhack007, yes. In Arduino-ESP32, a default-constructed IPAddress() has all four IPv4 octets set to zero. It represents 0.0.0.0.

The two changes address different conditions:

  • multiWiFi.size() prevents access to multiWiFi[0] when the vector is empty. This can be the crash fix if no Wi-Fi entry exists.
  • staticIP != IPAddress() and staticGW != IPAddress() compare two IPAddress objects. This selects the IPAddress comparison overload.

The old (uint32_t)0x00000000 value can convert to a null pointer. It then selects the const uint8_t * comparison overload shown in the Comment image. That overload reads the pointer as address bytes, so it can dereference nullptr.

Therefore, IPAddress() is the correct explicit test for 0.0.0.0, and multiWiFi.size() is the required bounds guard. Both changes are valid.
🐇🔍

You are interacting with an AI system.

ETH.config(multiWiFi[0].staticIP, multiWiFi[0].staticGW, multiWiFi[0].staticSN, dnsAddress);
} else {
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
Expand Down
Loading