diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-09-03 19:08:05 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-09-03 20:45:54 +0200 |
| commit | 9dcbf460ff692c049e4d327afcbdbc39ba4e8c65 (patch) | |
| tree | 1d96e2bccc566a3092768da691e7ca47881880de /tests | |
| parent | a3989fb9c5424f2f93c67669102ee8cb61303c24 (diff) | |
| download | tools.nes-9dcbf460ff692c049e4d327afcbdbc39ba4e8c65.tar.gz tools.nes-9dcbf460ff692c049e4d327afcbdbc39ba4e8c65.zip | |
Validate that memory access is done via variables
The address sanitizer is now able to detect whenever in an instruction a
memory access is done without using variables. This is now detected for
all instructions except for branching, which falls outside of this
scope.
Moreover, simple arithmetics is allowed and bounds are checked for
simple cases. That being said, more involved bound checks should be done
with other tools (e.g. emulators).
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bare_accesses.s | 37 | ||||
| -rw-r--r-- | tests/expected/bare_accesses.txt | 4 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/bare_accesses.s b/tests/bare_accesses.s new file mode 100644 index 0000000..42a6409 --- /dev/null +++ b/tests/bare_accesses.s @@ -0,0 +1,37 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $02 + .byte $01 + .byte $00 + .byte $00 + +.segment "CODE" + +.scope Scope + zp_valid = $02 + + .scope Inner + zp_valid_too = $03 + .endscope +.endscope + +zp_used = $00 ; asan:reserve $02 +whatever = $01 + +lda zp_used +lda $00 +lda whatever +lda Scope::zp_valid +lda Scope::Inner::zp_valid_too +lda zp_used + 1 +lda zp_used + 2 +lda zp_used - 1 + +@something: + beq @something + +ldx #0 +lda palettes, x + +palettes: + .byte $0F diff --git a/tests/expected/bare_accesses.txt b/tests/expected/bare_accesses.txt new file mode 100644 index 0000000..4c14629 --- /dev/null +++ b/tests/expected/bare_accesses.txt @@ -0,0 +1,4 @@ +warning: accessing a memory region without using a variable (bare_accesses.s: line 22) +warning: accessing a memory region without a proper name ('whatever') (bare_accesses.s: line 23) +error: out of bounds memory access for 'zp_used' ($00-$01) (bare_accesses.s: line 27) +error: out of bounds memory access for 'zp_used' ($00-$01) (bare_accesses.s: line 28) |
