From e5c32905d4afda1e71449f4672994a449fe98482 Mon Sep 17 00:00:00 2001 From: Kevin Weiss Date: Wed, 30 Sep 2026 11:06:17 +0200 Subject: [PATCH] fix(hlpr): parse hex files without an extended address record extract_identifier_from_hexfile only set extended_address on a type 04 record, so a valid Intel HEX file whose data records come first raised UnboundLocalError, which also escaped fw_id_from_fw_file's ValueError contract. Start at 0, as Intel HEX defines. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/lob_hlpr/hlpr.py | 2 ++ tests/test_lob_hlpr.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/lob_hlpr/hlpr.py b/src/lob_hlpr/hlpr.py index 2fb976b..3d58c07 100644 --- a/src/lob_hlpr/hlpr.py +++ b/src/lob_hlpr/hlpr.py @@ -326,6 +326,8 @@ def extract_identifier_from_hexfile(hex_str: str): segments = [] segment = bytearray() segment_address = None + # Without a type 04 record the upper address bits are zero + extended_address = 0 for idx, line in enumerate(hex_str.split("\n")): line = line.replace("\r", "") if line == "": diff --git a/tests/test_lob_hlpr.py b/tests/test_lob_hlpr.py index 769489a..3c9be07 100644 --- a/tests/test_lob_hlpr.py +++ b/tests/test_lob_hlpr.py @@ -136,6 +136,16 @@ def test_extract_identifier_no_hexinfo(): hlp.extract_identifier_from_hexfile(hex_str) +def test_extract_identifier_without_extended_address(): + """Data records before any extended address record start at address 0.""" + hex_str = "\n".join( + line for line in HEX_STRINGS[2].splitlines() if not line.startswith(":02000004") + ) + assert hlp.extract_identifier_from_hexfile(hex_str) == [ + "app-nrf9160-wmbus v0.23.6+hw3 TZ2 (Jan 27 2024 14:20:46)" + ] + + def test_log_print_passes(tmp_path, capsys): """Test log_print function with valid inputs.""" test_logger = logging.getLogger("test_logger")