Skip to content

Cast the MQTT handler, not its address, when applying changed config - #1279

Merged
gskjold merged 1 commit into
mainfrom
fix/mqtt-handler-config-cast
Oct 15, 2026
Merged

gskjold merged 1 commit into
mainfrom
fix/mqtt-handler-config-cast

Conversation

@gskjold

@gskjold gskjold commented Oct 15, 2026

Copy link
Copy Markdown
Member

Problem

In MQTT_connect(), when the MQTT config has changed but the payload format is unchanged, the existing handler is updated in place. For Domoticz (3) and Home Assistant (4) the code did:

DomoticzMqttHandler* dmh = (DomoticzMqttHandler*) &mqttHandler;
HomeAssistantMqttHandler* hamh = (HomeAssistantMqttHandler*) &mqttHandler;

&mqttHandler is the address of the global AmsMqttHandler* variable, not the handler object. setDomoticzConfig() and setHomeAssistantConfig() therefore wrote their fields (including String assignments for HA) into whatever globals sit next to mqttHandler, and the real handler kept its old Domoticz/HA config.

Fix

Cast mqttHandler itself.

Found while reviewing #1267, which fixes the getFormat() mismatch that previously made this path unreachable for some formats (for 3 and 4 it was always reachable).

Tested

Builds for esp8266 (flash 1 022 447 bytes, 97.9 %) and esp32. Not exercised on a device.

🤖 Generated with Claude Code

When the MQTT config changed but the payload format did not, MQTT_connect()
cast &mqttHandler (the address of the global pointer) to the Domoticz or
Home Assistant handler type. setDomoticzConfig() and setHomeAssistantConfig()
then wrote into the globals around that pointer instead of into the handler,
corrupting memory and leaving the handler on its old config.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: bfa44d2

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold
gskjold merged commit 36c35ed into main Oct 15, 2026
8 checks passed
@gskjold
gskjold deleted the fix/mqtt-handler-config-cast branch October 15, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant