Skip to content

Changed "(char *)&mac_dest" to "mac_dest.c_str()" in setMacDest() to … - #17

Merged
k3it merged 1 commit into
k3it:masterfrom
n1gp:master
Aug 6, 2026
Merged

k3it merged 1 commit into
k3it:masterfrom
n1gp:master

Conversation

@n1gp

@n1gp n1gp commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

…fix MAC Address DLL Filter.

The IP Address filter is working fine, but when I tried the MAC filter it didn't work.
This is what Gemini AI had to say:

Because mac_dest is a std::string, passing (char *)&mac_dest takes the memory address of the C++ class object itself, not the text inside it. This corrupts the data reading and can cause your program to crash. Correct Code Use the .c_str() method to safely access the underlying C-style string

It is working for me now with that change. I'm not sure why this may have been working fine in the past and not on my Win10 X64 platform.

@k3it k3it left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approving — this is a correct, minimal fix for genuine undefined behavior.

mac_dest is a std::string, so (char *)&mac_dest passed the address of the string object into sscanf, causing it to parse the string's internal control structure rather than the text. That it worked on some builds is explained by MSVC's small-string optimization happening to place the inline character buffer at the start of the object — fragile and layout/compiler-dependent, which is why it broke on Win10 x64. mac_dest.c_str() returns a proper pointer to the null-terminated character data, so the fix is correct and portable.

It also brings setMacDest() in line with the neighboring setBcastDest(), which already uses bcast_dest.c_str() — explaining why the IP filter worked while the MAC filter didn't. The mac_dest.size() == 4 guard plus the null-terminated c_str() keeps the %2hhX%2hhX read safely in bounds.

Thanks for the fix.


Generated by Claude Code

@k3it
k3it merged commit 16d1b0d into k3it:master Aug 6, 2026
1 check passed
n1gp pushed a commit to n1gp/HermesIntf that referenced this pull request Sep 4, 2026
- Bump version to 26.8.9 in hermes.rc (FILEVERSION/PRODUCTVERSION + strings)
- Add 26.8.9 changelog entry to readme.txt for PR k3it#16 (TRX-DUO/Red Pitaya
  Protocol 2 fixes, P2 watchdog feed) and PR k3it#17 (fix MAC address DLL filter)
- msbuild.yml: upload built HermesIntf.dll as a workflow artifact and
  auto-attach it to published GitHub releases

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SsVwSNXUxxufvxfb63DbT4
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.

2 participants