Fix address-truthiness bugs around a valid 0x0 - #1
Open
ppannuto-claude wants to merge 1 commit into
Open
Conversation
Several places in the codebase distinguish "no address given/known" from "an address was given/known" using plain truthiness (`if addr:`) on a value that is `None` when unset. That conflates "unset" with an address of exactly `0x0`, which is a normal, valid flash and/or app base address (e.g. any Cortex-M board, or Tock's qemu_arm_mps2 boards). Fix all of these to check `is not None` instead: - `main.py` `command_local_board_set()`: an explicit `--app-address 0x0`/`--flash-address 0x0` was validated but then silently omitted from the status output, making it look like the flag was ignored. - `flash_file.py` `set_local_board()`: the same values were then silently dropped from the persisted `local-board` TOML config, discarding the deliberate setting entirely. - `flash_file.py` `FlashFile.get_flash_address()`: a stored `flash_address == 0` was reported as `None` (unknown) instead of `0`. - `board_interface.py` `BoardInterface.get_apps_start_address()`: a configured `app_address == 0` was ignored in favor of querying the board's `appaddr` attribute (or returning `None` if that's absent). - `tockloader.py` `_get_apps_start_address()`: a cached value of `0`, an explicit `--app-address 0x0` on any command (not just `local-board set`), or a channel-reported address of `0` were all treated as "unknown" and silently overridden by lower-priority defaults. - `tockloader.py` `_get_flash_start_address()`: a channel-reported flash address of `0` was treated as "unknown" and replaced with the function's own hardcoded `0` default -- harmless today only because that default happens to also be `0`. - `tockloader.py` `_get_memory_start_address()`: same cached-value pattern as above, for the app RAM start address. Verified with `local-board set zerotest --arch cortex-m3 --app-address 0x0 --flash-address 0x0`: both values now appear in the status output and are correctly persisted as `0` (not omitted) in the TOML config. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTQ6pWrckM3jp9vfBo4bhk
ppannuto-claude
force-pushed
the
fix/local-board-zero-address
branch
from
September 1, 2026 19:11
d3ff1a2 to
654fa20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several places in tockloader distinguish "no address given/known" from
"an address was given/known" using plain truthiness (
if addr:) on avalue that is
Nonewhen unset. That conflates "unset" with an addressof exactly
0x0, which is a normal, valid flash and/or app base address(e.g. any Cortex-M board, or Tock's
qemu_arm_mps2boards) — foundwhile getting
qemu_arm_mps2working withtockloader local-board.Fixed all instances of this pattern to check
is not Noneinstead:main.pycommand_local_board_set(): an explicit--app-address 0x0/--flash-address 0x0was validated but then silently omittedfrom the status output, making it look like the flag was ignored.
flash_file.pyset_local_board(): the same values were thensilently dropped from the persisted
local-boardTOML config,discarding the deliberate setting entirely.
flash_file.pyFlashFile.get_flash_address(): a storedflash_address == 0was reported asNone(unknown) instead of0.board_interface.pyBoardInterface.get_apps_start_address(): aconfigured
app_address == 0was ignored in favor of querying theboard's
appaddrattribute (or returningNoneif that's absent).tockloader.py_get_apps_start_address(): a cached value of0,an explicit
--app-address 0x0on any command (not justlocal-board set), or a channel-reported address of0were alltreated as "unknown" and silently overridden by lower-priority
defaults.
tockloader.py_get_flash_start_address(): a channel-reportedflash address of
0was treated as "unknown" and replaced with thefunction's own hardcoded
0default -- harmless today only becausethat default happens to also be
0.tockloader.py_get_memory_start_address(): same cached-valuepattern as above, for the app RAM start address.
Note: a related but distinct bug in
_reshuffle_apps()(a debug-logformat string crashing on a
NoneRAM address) is being trackedseparately upstream as tock#141 and is not part of this PR.
Test plan
python3 -m tockloader.main local-board set zerotest --arch cortex-m3 --app-address 0x0 --flash-address 0x0— confirmed bothvalues now appear in the status output and are correctly
persisted as
0(not omitted) in the TOML config.--version/list-known-boards). The remaining sites(
_get_apps_start_address,_get_flash_start_address,_get_memory_start_address,get_apps_start_address) werereviewed by inspection and are the same fix pattern, but not
individually exercised against real hardware/QEMU in this
session.
AI use disclosure
This PR was written primarily by Claude Code (Anthropic's Claude Sonnet
5). Claude was given a human-authored bug report describing the
original
local-boardtruthiness bug with exact file/line locations,then asked to audit the rest of the codebase for the same bug class,
which surfaced the additional sites above; a human then directed which
fixes to apply and how to structure the commit. Reviewed by the
submitter before opening/updating.
Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
🤖 Generated with Claude Code
https://claude.ai/code/session_01KTQ6pWrckM3jp9vfBo4bhk