Skip to content

TODO fixes: safe CLI merge and typed start address - #40

Merged
iharhl merged 2 commits into
masterfrom
feature/todo-fixes
Nov 17, 2026
Merged

iharhl merged 2 commits into
masterfrom
feature/todo-fixes

Conversation

@iharhl

@iharhl iharhl commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Resolves two of the open TODOs: hexcli merge no longer overwrites overlapping data silently, and the start address record is stored as a typed value instead of raw record text.

hexcli merge

  • Uses merge_safe by default: overlapping data or differing start address records stop the merge with an error that names the file, e.g. app.hex overlaps an earlier input at 0x100 (use --overwrite ...). No output file is written. Before, the later input won without a word, so a wrong :addr could corrupt another image
  • New --overwrite switch restores the old behavior (later inputs replace overlapping data and the start address record)
  • Warning when a .hex input with a start address record is moved with :addr: relocation moves only the data, so the merged file may point to the old entry point. No warning if :addr equals where the data already starts
  • parse_args supports switches (flags without a value) via SWITCH_FLAGS. Unsupported / repeated switches are rejected like other flags

Start address record

  • IntelHex::start_addr is Option<StartAddress> instead of Option<[u8; 18]> (the record's ASCII text). Breaking change of the library API
  • New public StartAddress enum: Segment { cs, ip } (record type 03) and Linear(u32) (record type 05, EIP), with record_type(), to_bytes() and Display (0x11223344 (EIP), 0xF000:0x000A (CS:IP))
  • write_hex creates the record from the value, so it is always uppercase with a valid checksum. Before, the input text was copied as is (a lowercase record stayed lowercase)
  • merge_safe compares values: the same start address written in upper and lower case is no longer a conflict
  • hexcli info shows the start address if the file has one
  • fingerprint.rs keeps working unchanged (StartAddress derives Hash)

Tests

  • CLI: overlap fails by default / works with --overwrite, differing start addresses fail by default / later one kept with --overwrite, identical start addresses accepted, relocation warning shown / not shown, --overwrite rejected by convert and when repeated, info shows the start address
  • An existing merge test merged overlapping inputs and relied on the silent overwrite; it now passes --overwrite
  • intelhex.rs: parsing both start record types and lowercase input, merge of start addresses differing only in case, write_hex round trip for both types. Existing tests use StartAddress values instead of raw byte arrays
  • record.rs: StartAddress from a record, record type and payload bytes, display text
  • update_slice failure test also checks that the buffer is left unchanged (replaces a todo: fail comment)

@iharhl
iharhl merged commit 6e5767b into master Nov 17, 2026
5 checks passed
@iharhl
iharhl deleted the feature/todo-fixes branch November 17, 2026 23:07
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