MOVE: do not crash when u is 0 (#126)
This commit adds ?DUP IF guards to MOVE and MOVE- that make them exit when u is 0. Without these guards a DO loop was executed 65535 times instead of 0. In particular, this fixes a crash when "105 LOAD I " is executed immediately after boot. Block editor word "I" passes IBUF length (0) to MOVE- and MOVE in this case, causing a crash.
This commit is contained in:
parent
99c05fff3c
commit
d83d12899b
8
blk/370
8
blk/370
@ -1,15 +1,15 @@
|
||||
: MOVE ( a1 a2 u -- )
|
||||
( u ) 0 DO ( a1 a2 )
|
||||
?DUP IF ( u ) 0 DO ( a1 a2 )
|
||||
SWAP C@+ ( a2 a1+1 x )
|
||||
ROT C!+ ( a1+1 a2+1 )
|
||||
LOOP 2DROP ;
|
||||
LOOP THEN 2DROP ;
|
||||
: MOVE- ( a1 a2 u -- )
|
||||
TUCK + 1- ( a1 u a2+u-1 )
|
||||
?DUP IF TUCK + 1- ( a1 u a2+u-1 )
|
||||
ROT 2 PICK + 1- ( u a2+u-1 a1+u-1 )
|
||||
ROT ( u ) 0 DO ( a2 a1 )
|
||||
C@- ( a2 a1-1 x )
|
||||
ROT C!- ( a1-1 a2-1 ) SWAP ( a2 a1 )
|
||||
LOOP 2DROP ;
|
||||
LOOP THEN 2DROP ;
|
||||
: MOVE, ( a u -- ) H@ OVER ALLOT SWAP MOVE ;
|
||||
: PREV 3 - DUP @ - ;
|
||||
|
||||
|
BIN
emul/forth.bin
BIN
emul/forth.bin
Binary file not shown.
Loading…
Reference in New Issue
Block a user