Skip to content

Remove the toHex overload that takes its length from a pointer's size - #1312

Merged
gskjold merged 1 commit into
mainfrom
remove-pointer-sized-tohex
Nov 5, 2026
Merged

gskjold merged 1 commit into
mainfrom
remove-pointer-sized-tohex

Conversation

@gskjold

@gskjold gskjold commented Nov 5, 2026

Copy link
Copy Markdown
Member

Why

toHex(uint8_t* in) computed its byte count as sizeof(in)*2, i.e. the size of the pointer, not the buffer behind it. On ESP8266/ESP32 (32-bit) that is 8. Its only caller, RawMqttHandler::publishTemperatures, passes an 8-byte DS18B20 address (TempSensorData::address[8]), so the published topic was correct by accident. Any other buffer size, or a 64-bit native build, would read the wrong number of bytes.

Changes

  • Remove the one-argument toHex from hexutils.h/.cpp.
  • RawMqttHandler calls toHex(data->address, 8), the same as the address call sites in JsonMqttHandler and AmsWebServer.

No behaviour change on devices: the raw MQTT temperature topic stays the same.

Verification

  • pio run -e esp32 -e esp8266 builds. With the overload removed, any remaining caller would fail to compile.
  • pio test -e native: 25/25 pass.

🤖 Generated with Claude Code

toHex(uint8_t*) used sizeof(in)*2 as the byte count, which is the size
of the pointer, not of the buffer. On the 32-bit ESP targets that is 8,
which happens to match the one caller, the 8-byte temperature sensor
address in the raw MQTT handler, so the output was right by accident.
Pass the length explicitly there, as the other address call sites do,
and drop the overload so it cannot be misused.

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

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: 48263f1

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold
gskjold merged commit 5454532 into main Nov 5, 2026
8 checks passed
@gskjold
gskjold deleted the remove-pointer-sized-tohex branch November 5, 2026 15: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