Skip to content

Fix off-by-one error on valid I/O addresses - #590

Merged
gatk555 merged 1 commit into
buserror:masterfrom
edgar-bonet:off-by-one
Sep 26, 2026
Merged

gatk555 merged 1 commit into
buserror:masterfrom
edgar-bonet:off-by-one

Conversation

@edgar-bonet

Copy link
Copy Markdown
Contributor

In sim_core.c, there are two instances where an address is determined to be a valid I/O address with this test:

if (addr > 31 && addr < 31 + MAX_IOs)

However, the range of valid I/O addresses is 32 – (MAX_IOs+31) inclusive. Thus, the upper bound in the above test should be included.

This pull request fixes the error. This could be done by replacing < with <= in the second comparison. Instead, I chose to write

if (addr >= 32 && addr < MAX_IOs + 32)

because:

  1. index ranges defined as left-closed, right-open intervals, like [a, b), are more idiomatic in C than their reversed counterparts

  2. this is stylistically more consistent with the test if (addr < MAX_IOs + 32) in _avr_set_ram().

The range of valid I/O addresses is 32..MAX_IOs+31.
@gatk555
gatk555 merged commit d6aed53 into buserror:master Sep 26, 2026
8 checks passed
@edgar-bonet
edgar-bonet deleted the off-by-one branch September 26, 2026 15:57
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