summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-07 20:13:24 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-07 20:13:24 (GMT)
commit73229a7e53190161f9fac4c02158d6a20645eab0 (patch)
tree741cf370f0a04a846db70ed678808dc7c7cf9026 /generic/tclIO.c
parentf4618fc2d91563021eaec2308d4c7ff326e4e0e7 (diff)
parent9aea48988c29a181e815be248de624c7bf29d5bc (diff)
downloadtcl-73229a7e53190161f9fac4c02158d6a20645eab0.zip
tcl-73229a7e53190161f9fac4c02158d6a20645eab0.tar.gz
tcl-73229a7e53190161f9fac4c02158d6a20645eab0.tar.bz2
Merge 9.0
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index dc0ce7d..dd05ee3 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -191,9 +191,9 @@ static int DetachChannel(Tcl_Interp *interp, Tcl_Channel chan);
static void DiscardInputQueued(ChannelState *statePtr,
int discardSavedBuffers);
static void DiscardOutputQueued(ChannelState *chanPtr);
-static int DoRead(Channel *chanPtr, char *dst, Tcl_Size bytesToRead,
+static Tcl_Size DoRead(Channel *chanPtr, char *dst, Tcl_Size bytesToRead,
int allowShortReads);
-static int DoReadChars(Channel *chan, Tcl_Obj *objPtr, Tcl_Size toRead,
+static Tcl_Size DoReadChars(Channel *chan, Tcl_Obj *objPtr, Tcl_Size toRead,
int appendFlag);
static int FilterInputBytes(Channel *chanPtr,
GetsState *statePtr);
@@ -5905,11 +5905,11 @@ Tcl_ReadChars(
*---------------------------------------------------------------------------
*/
-static int
+static Tcl_Size
DoReadChars(
Channel *chanPtr, /* The channel to read. */
Tcl_Obj *objPtr, /* Input data is stored in this object. */
- Tcl_Size toRead, /* Maximum number of characters to store, or
+ Tcl_Size toRead, /* Maximum number of characters to store, or
* TCL_INDEX_NONE to read all available data (up to EOF or
* when channel blocks). */
int appendFlag) /* If non-zero, data read from the channel
@@ -5920,7 +5920,8 @@ DoReadChars(
ChannelState *statePtr = chanPtr->state;
/* State info for channel */
ChannelBuffer *bufPtr;
- int copied, copiedNow, result;
+ Tcl_Size copied;
+ int result;
Tcl_Encoding encoding = statePtr->encoding;
int binaryMode;
#define UTF_EXPANSION_FACTOR 1024
@@ -6005,8 +6006,8 @@ DoReadChars(
}
ResetFlag(statePtr, CHANNEL_BLOCKED|CHANNEL_EOF);
statePtr->inputEncodingFlags &= ~TCL_ENCODING_END;
- for (copied = 0; toRead > 0; ) {
- copiedNow = -1;
+ for (copied = 0; toRead > 0 || toRead == TCL_INDEX_NONE; ) {
+ int copiedNow = -1;
if (statePtr->inQueueHead != NULL) {
if (binaryMode) {
copiedNow = ReadBytes(statePtr, objPtr, toRead);
@@ -6052,7 +6053,9 @@ DoReadChars(
}
} else {
copied += copiedNow;
- toRead -= copiedNow;
+ if (toRead != TCL_INDEX_NONE) {
+ toRead -= copiedNow; /* Only decr if not reading whole file */
+ }
}
}
@@ -6228,7 +6231,7 @@ ReadChars(
size_t size;
dst = TclGetStringStorage(objPtr, &size) + numBytes;
- dstLimit = size - numBytes;
+ dstLimit = (size - numBytes) > INT_MAX ? INT_MAX : (size - numBytes);
} else {
dst = TclGetString(objPtr) + numBytes;
}
@@ -9604,9 +9607,10 @@ CopyData(
Tcl_Obj *cmdPtr, *errObj = NULL, *bufObj = NULL, *msg = NULL;
Tcl_Channel inChan, outChan;
ChannelState *inStatePtr, *outStatePtr;
- int result = TCL_OK, size;
+ int result = TCL_OK;
Tcl_Size sizeb;
Tcl_WideInt total;
+ Tcl_WideInt size; /* TODO - be careful if total and size are made unsigned */
const char *buffer;
int inBinary, outBinary, sameEncoding;
/* Encoding control */
@@ -9944,7 +9948,7 @@ CopyData(
*----------------------------------------------------------------------
*/
-static int
+static Tcl_Size
DoRead(
Channel *chanPtr, /* The channel from which to read. */
char *dst, /* Where to store input read. */