From 768fa22c43bfd6228f6e09e81dfebed70c1a9244 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 9 Dec 2022 10:22:11 +0000 Subject: Partial solution for [b8f575aa23]. Still missing: 1) testcases. 2) What if both EOF and ENCODING_ERROR happens (because there is both an eofchar and an invalid byte in the stream) --- generic/tclIO.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 8e4ecee..afe6aec 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7588,7 +7588,7 @@ Tcl_Eof( ChannelState *statePtr = ((Channel *) chan)->state; /* State of real channel structure. */ - return GotFlag(statePtr, CHANNEL_EOF) ? 1 : 0; + return (GotFlag(statePtr, CHANNEL_EOF) && !GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) ? 1 : 0; } /* -- cgit v0.12 From ae31cee4ae595cd1a16f50df82add275c41d8cde Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 9 Dec 2022 14:53:25 +0000 Subject: Add 2 unit-tests, for the 2 cornercases mentioned in the TIP. This shows that the fix works as expected --- tests/io.test | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/io.test b/tests/io.test index c58bbce..d4839f5 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9065,6 +9065,46 @@ test io-75.6 {invalid utf-8 encoding read is not ignored (-strictencoding 1)} -s removeFile io-75.6 } -match glob -result {41 1 {error reading "*": illegal byte sequence}} +test io-75.7 {invalid utf-8 encoding eof handling (-strictencoding 1)} -setup { + set fn [makeFile {} io-75.7] + set f [open $fn w+] + fconfigure $f -encoding binary + # \x81 is invalid in utf-8. -eofchar is not detected, because it comes later. + puts -nonewline $f "A\x81\x1A" + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -strictencoding 1 +} -body { + set d [read $f] + binary scan $d H* hd + lappend hd [eof $f] + lappend hd [catch {read $f} msg] + close $f + lappend hd $msg +} -cleanup { + removeFile io-75.6 +} -match glob -result {41 0 1 {error reading "*": illegal byte sequence}} + +test io-75.8 {invalid utf-8 encoding eof handling (-strictencoding 1)} -setup { + set fn [makeFile {} io-75.8] + set f [open $fn w+] + fconfigure $f -encoding binary + # \x81 is invalid in utf-8, but since \x1A comes first, -eofchar takes precedence. + puts -nonewline $f "A\x1A\x81" + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -strictencoding 1 +} -body { + set d [read $f] + binary scan $d H* hd + lappend hd [eof $f] + lappend hd [read $f] + close $f + set hd +} -cleanup { + removeFile io-75.6 +} -result {41 1 {}} + # ### ### ### ######### ######### ######### -- cgit v0.12 From 4f69a6f297bc3013c0c00a24db52fd34a59f902e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 9 Dec 2022 19:55:38 +0000 Subject: Fix compilation with tcc. Thanks, Cyan Ogilvie for the report --- generic/tcl.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index da3d1f0..f373382 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -156,8 +156,13 @@ extern "C" { # endif #else # define TCL_FORMAT_PRINTF(a,b) -# define TCL_NORETURN _declspec(noreturn) -# define TCL_NOINLINE __declspec(noinline) +# if defined(_MSC_VER) +# define TCL_NORETURN _declspec(noreturn) +# define TCL_NOINLINE __declspec(noinline) +# else +# define TCL_NORETURN /* nothing */ +# define TCL_NOINLINE /* nothing */ +# endif # define TCL_NORETURN1 /* nothing */ #endif -- cgit v0.12