Skip to content

tockloader: fix address-truthiness bugs around a valid 0x0 - #142

Merged
bradjc merged 2 commits into
masterfrom
fix_truthiness_addr0_checks
Sep 2, 2026
Merged

tockloader: fix address-truthiness bugs around a valid 0x0#142
bradjc merged 2 commits into
masterfrom
fix_truthiness_addr0_checks

Conversation

@ppannuto

@ppannuto ppannuto commented Sep 1, 2026

Copy link
Copy Markdown
Member

Update if checks around addresses to explicitly compare to None, so that an address of 0x0 doesn't accidentally evaluate as False.

Claude's essay

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.

Claude-Session: https://claude.ai/code/session_01KTQ6pWrckM3jp9vfBo4bhk

ppannuto-claude and others added 2 commits September 1, 2026 12:15
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
@bradjc
bradjc merged commit edf39ef into master Sep 2, 2026
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.

3 participants