Skip to content

Commit

Permalink
GH-14 Fix LOAD infinite loop input handling in p4Refill() and
Browse files Browse the repository at this point in the history
p4Accept(); add start of Block word test suite.
  • Loading branch information
SirWumpus committed Aug 9, 2024
1 parent 158fe99 commit 387f56f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
36 changes: 36 additions & 0 deletions test/block.p4
Original file line number Diff line number Diff line change
@@ -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]

1 change: 1 addition & 0 deletions test/units.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 387f56f

Please sign in to comment.