_type: exit if input is not available

Currently when

  BUF _type

is executed, if there is a newline immediately after _type, no input is
available. C< returns 0, and it is stored in the buffer.  _type then
proceeds to read until another newline is reached, and the resulting
buffer contents looks like "\x00xyz\x0d" (in C string notation).

This change makes _type exit early in this case and keep the buffer
unchanged.

_type is used by editor words such as I and F, so this bug affects them
as well.
This commit is contained in:
Alexander Krotov 2020-06-20 01:41:45 +03:00
parent 723d3c4249
commit 132bc8f41c
1 changed files with 1 additions and 1 deletions

View File

@ -1,4 +1,5 @@
: _type ( buf -- )
C<? NOT IF DROP EXIT THEN
C< DUP 0xd = IF 2DROP EXIT THEN SWAP DUP _zbuf ( c a )
BEGIN ( c a ) C!+ C< TUCK 0x0d = UNTIL ( c a ) C! ;
( user-facing lines are 1-based )
@ -13,4 +14,3 @@