From 4e43d260f93216348337518eaead94855b2dadbf Mon Sep 17 00:00:00 2001 From: andreas_kupries Date: Thu, 12 Nov 2009 17:41:30 +0000 Subject: * generic/tclIO.c (CopyData): [Bug 2895565]. Dropped bogosity * tests/io.test: which used the number of _written_ bytes or character to update the counters for the read bytes/characters. New test io-53.11. This is a backward port from the 8.5 branch. --- ChangeLog | 9 ++++++++- generic/tclIO.c | 17 ++++++++++++----- tests/io.test | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa1f3ac..40bda77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-11-12 Andreas Kupries + + * generic/tclIO.c (CopyData): [Bug 2895565]. Dropped bogosity + * tests/io.test: which used the number of _written_ bytes or + character to update the counters for the read bytes/characters. + New test io-53.11. This is a backward port from the 8.5 branch. + 2009-11-10 Pat Thoyts * tests/fCmd.test: Fixed a number of issues for Vista @@ -11,7 +18,7 @@ 2009-11-10 Andreas Kupries - * generic/tclObj.c: Plus memory leak in TclContinuationsEnter(). + * generic/tclObj.c: Plug memory leak in TclContinuationsEnter(). [Bug 2895323]. Backport from Tcl 8.5 branch, change by Don Porter. 2009-11-09 Andreas Kupries diff --git a/generic/tclIO.c b/generic/tclIO.c index 11cb205..c6d5c36 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIO.c,v 1.61.2.33 2009/10/23 19:08:45 andreas_kupries Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.61.2.34 2009/11/12 17:41:30 andreas_kupries Exp $ */ #include "tclInt.h" @@ -7936,10 +7936,17 @@ CopyData(csPtr, mask) sizeb = DoWriteChars(outStatePtr->topChanPtr, buffer, sizeb); } - if (inBinary || sameEncoding) { - /* Both read and write counted bytes */ - size = sizeb; - } /* else : Read counted characters, write counted bytes, i.e. size != sizeb */ + /* + * [Bug 2895565]. At this point 'size' still contains the number of + * bytes or characters which have been read. We keep this to later to + * update the totals and toRead information, see marker (UP) below. We + * must not overwrite it with 'sizeb', which is the number of written + * bytes or characters, and both EOL translation and encoding + * conversion may have changed this number unpredictably in relation + * to 'size' (It can be smaller or larger, in the latter case able to + * drive toRead below -1, causing infinite looping). Completely + * unsuitable for updating totals and toRead. + */ if (sizeb < 0) { writeError: diff --git a/tests/io.test b/tests/io.test index 1a0f72e..9c94864 100644 --- a/tests/io.test +++ b/tests/io.test @@ -13,7 +13,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: io.test,v 1.40.2.23 2008/06/20 16:49:11 dgp Exp $ +# RCS: @(#) $Id: io.test,v 1.40.2.24 2009/11/12 17:41:31 andreas_kupries Exp $ if {[catch {package require tcltest 2}]} { puts stderr "Skipping tests in [info script]. tcltest 2 required." @@ -7158,6 +7158,37 @@ test io-53.10 {Bug 1350564, multi-directional fcopy} -setup { removeFile err catch {unset ::forever} } -result {AB BA} +test io-53.11 {Bug 2895565} -setup { + set in [makeFile {} in] + set f [open $in w] + fconfigure $f -encoding utf-8 -translation binary + puts -nonewline $f [string repeat "Ho hum\n" 11] + close $f + set inChan [open $in r] + fconfigure $inChan -translation binary + set out [makeFile {} out] + set outChan [open $out w] + fconfigure $outChan -encoding cp1252 -translation crlf + proc CopyDone {bytes args} { + variable done + if {[llength $args]} { + set done "Error: '[lindex $args 0]' after $bytes bytes copied" + } else { + set done "$bytes bytes copied" + } + } +} -body { + variable done + after 2000 [list set [namespace which -variable done] timeout] + fcopy $inChan $outChan -size 40 -command [namespace which CopyDone] + vwait [namespace which -variable done] + set done +} -cleanup { + close $outChan + close $inChan + removeFile out + removeFile in +} -result {40 bytes copied} test io-54.1 {Recursive channel events} {socket fileevent} { # This test checks to see if file events are delivered during recursive -- cgit v0.12