Subject: Re: dejagnu-1.6.3 test failure

From: Adam Sampson <[email-masked]>
Date: Sat, 23 Oct 2021 01:10:46 +0100

(I've just sent this to the mailing list, but so it's in the bug report
as well...)

Jacob Bachmeyer <[email-masked]> writes:

> Expect is incorrectly treating a line exactly 64 bytes long as EOF.

I've just run into this as well when packaging 1.6.3 -- for me, it
happens on Linux 5.10 but not on Linux 4.19, where expect's read(0, buf,
4096) call reads 65 bytes including the newline. So I guess it's become
visible as a result of some change in Linux tty behaviour...

After a bit of debugging, the cause seems to be that expect uses
Tcl_GetsObj to read from stdin, and treats a -1 return value as an
error. However, Tcl_GetsObj can also return -1 to indicate that input
was blocked, i.e. it didn't manage to read a complete line -- expect
didn't handle this case.

This patch seems to fix the problem:

--- expect5.45.4/exp_main_sub.c	2018-02-04 10:43:58.000000000 +0000
+++ expect5.45.4/exp_main_sub.c	2021-10-23 00:39:09.375404444 +0100
@@ -326,7 +326,9 @@
 
 	if (code != EXP_EOF) {
 	    inChannel = expStdinoutGet()->channel;
-	    code = Tcl_GetsObj(inChannel, commandPtr);
+	    do {
+		code = Tcl_GetsObj(inChannel, commandPtr);
+	    } while (code < 0 && Tcl_InputBlocked(inChannel));
 #ifdef SIMPLE_EVENT
 	    if (code == -1 && errno == EINTR) {
 		if (Tcl_AsyncReady()) {

(expect experts may have a better solution, of course!)

Thanks,

-- 
Adam Sampson <[email-masked]>                         <http://offog.org/>