Skip to content

Commit a2d5025

Browse files
handle invalid slots from the user in the fileioc api
1 parent dc410e7 commit a2d5025

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/fileioc/fileioc.asm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,14 +876,11 @@ ti_Close:
876876
pop de
877877
pop bc
878878
push bc
879-
ld b, 3
880-
mlt bc
881-
ld hl, variable_offsets - 1
882-
add hl, bc
883-
; upper byte of offset = slot * 3
884-
ld (hl), c
885-
ex de, hl
886-
jp (hl)
879+
push de
880+
call util_is_slot_open
881+
jq nz, util_ret_null
882+
ld (hl), 255
883+
ret
887884

888885
;-------------------------------------------------------------------------------
889886
ti_DetectAny:
@@ -1550,6 +1547,8 @@ util_is_slot_open:
15501547
; zf = open
15511548
; (curr_slot) = slot
15521549
ld a, c
1550+
cp a, 6
1551+
jr nc, .not_open
15531552
ld (curr_slot), a
15541553
ld b, 3
15551554
mlt bc
@@ -1558,6 +1557,10 @@ util_is_slot_open:
15581557
ld a, b
15591558
cp a, (hl)
15601559
ret
1560+
.not_open:
1561+
xor a, a
1562+
inc a
1563+
ret
15611564

15621565
util_get_vat_ptr:
15631566
ld a, (curr_slot)
@@ -1636,5 +1639,6 @@ util_post_gc_handler := $-3
16361639
; Internal library data
16371640
;-------------------------------------------------------------------------------
16381641

1642+
db 255 ; handle edge case of 0 for slot
16391643
variable_offsets:
16401644
dl -1, -1, -1, -1, -1

0 commit comments

Comments
 (0)