From 387f56f659521d52c874bab650809560d5b676f4 Mon Sep 17 00:00:00 2001 From: Anthony Howe Date: Fri, 9 Aug 2024 16:53:29 -0400 Subject: [PATCH] GH-14 Fix `LOAD` infinite loop input handling in p4Refill() and p4Accept(); add start of Block word test suite. --- src/post4.c | 2 +- test/block.p4 | 36 ++++++++++++++++++++++++++++++++++++ test/units.p4 | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/block.p4 diff --git a/src/post4.c b/src/post4.c index 5762c98..284360e 100755 --- a/src/post4.c +++ b/src/post4.c @@ -859,7 +859,7 @@ p4Accept(P4_Input *input, P4_Char *buf, P4_Size size) P4_Char *ptr; if (input->fp == (FILE *) -1 || size-- <= 1) { - return 0; + return EOF; } #ifdef HAVE_TCSETATTR /* For a terminal restore original line input and echo settings. */ diff --git a/test/block.p4 b/test/block.p4 new file mode 100644 index 0000000..ceb7f2c --- /dev/null +++ b/test/block.p4 @@ -0,0 +1,36 @@ +INCLUDE ../test/assert.p4 + +[UNDEFINED] BLOCK-OPEN [IF] + +.( Block file support disabled. ) CR + +[ELSE] + +MARKER rm_block_tests + +: tw_tmp_blk S" /tmp/tmp.blk" ; + +.( BLOCK-OPEN BLOCK-CLOSE ) test_group +t{ tw_tmp_blk BLOCK-OPEN -> TRUE }t +\ t{ :NONAME 1 LOAD ; CATCH -> -33 }t +t{ BLOCK-CLOSE -> }t +t{ tw_tmp_blk DELETE-FILE -> 0 }t +test_group_end + +.( BLK BUFFER UPDATE SAVE-BUFFERS ) test_group +t{ tw_tmp_blk BLOCK-OPEN + 1 BUFFER DUP 1024 BLANK + CHAR ^ PARSE S" SOURCE-ID BLK @ " EVALUATE ^ ROT SWAP CMOVE + UPDATE SAVE-BUFFERS BLOCK-CLOSE +-> TRUE }t +test_group_end + +.( LOAD ) test_group +t{ tw_tmp_blk BLOCK-OPEN 1 LOAD -> TRUE -1 0 }t +t{ BLOCK-CLOSE tw_tmp_blk DELETE-FILE -> 0 }t +test_group_end + +rm_block_tests + +[THEN] + diff --git a/test/units.p4 b/test/units.p4 index f7ba8d9..bde54f5 100644 --- a/test/units.p4 +++ b/test/units.p4 @@ -16,6 +16,7 @@ INCLUDE ../test/string.p4 INCLUDE ../test/tools.p4 INCLUDE ../test/facility.p4 + INCLUDE ../test/block.p4 INCLUDE ../test/file.p4 INCLUDE ../test/exceptions.p4 test_suite_end