summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-02-06 19:04:36 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-02-06 19:04:36 (GMT)
commit11b2556b272a74d9456a2b0b9cef5ccc76fd8316 (patch)
tree0200708c41644616f3064cf13f8525b0194b9899 /generic
parent204a41c65d68c707c0b4e6114424444c59e75808 (diff)
downloadtcl-11b2556b272a74d9456a2b0b9cef5ccc76fd8316.zip
tcl-11b2556b272a74d9456a2b0b9cef5ccc76fd8316.tar.gz
tcl-11b2556b272a74d9456a2b0b9cef5ccc76fd8316.tar.bz2
Revised ReadChars to restore an attempt to make sure we do not short readdgp_may_be_pointless
because of a false notion of limited storage space. The test suite does not appear to demonstrate any case where this matters. Could be an incomplete test suite, or an example of pointless code.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c8
-rw-r--r--generic/tclInt.h2
-rw-r--r--generic/tclStringObj.c32
3 files changed, 41 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index f8baba3..cedf3f6 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -5310,7 +5310,13 @@ ReadChars(
dstNeeded = TCL_UTF_MAX - 1 + toRead * factor / UTF_EXPANSION_FACTOR;
(void) TclGetStringFromObj(objPtr, &numBytes);
Tcl_AppendToObj(objPtr, NULL, dstNeeded);
- dst = TclGetString(objPtr) + numBytes;
+ if (toRead == srcLen) {
+ unsigned int size;
+ dst = TclGetStringStorage(objPtr, &size) + numBytes;
+ dstNeeded = size - numBytes;
+ } else {
+ dst = TclGetString(objPtr) + numBytes;
+ }
/*
* [Bug 1462248]: The cause of the crash reported in this bug is this:
diff --git a/generic/tclInt.h b/generic/tclInt.h
index a998460..0c09ec0 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2571,6 +2571,8 @@ MODULE_SCOPE int TclGetOpenModeEx(Tcl_Interp *interp,
int *binaryPtr);
MODULE_SCOPE Tcl_Obj * TclGetProcessGlobalValue(ProcessGlobalValue *pgvPtr);
MODULE_SCOPE const char *TclGetSrcInfoForCmd(Interp *iPtr, int *lenPtr);
+MODULE_SCOPE char * TclGetStringStorage(Tcl_Obj *objPtr,
+ unsigned int *sizePtr);
MODULE_SCOPE int TclGlob(Tcl_Interp *interp, char *pattern,
Tcl_Obj *unquotedPrefix, int globFlags,
Tcl_GlobTypeData *types);
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index d96d814..8c6a376 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -2711,6 +2711,38 @@ Tcl_ObjPrintf(
/*
*---------------------------------------------------------------------------
*
+ * TclGetStringStorage --
+ *
+ * Returns the string storage space of a Tcl_Obj.
+ *
+ * Results:
+ * The pointer value objPtr->bytes is returned and the number of bytes
+ * allocated there is written to *sizePtr (if known).
+ *
+ * Side effects:
+ * May set objPtr->bytes.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+char *
+TclGetStringStorage(
+ Tcl_Obj *objPtr,
+ unsigned int *sizePtr)
+{
+ String *stringPtr;
+
+ if (objPtr->typePtr != &tclStringType || objPtr->bytes == NULL) {
+ return TclGetStringFromObj(objPtr, (int *)sizePtr);
+ }
+
+ stringPtr = GET_STRING(objPtr);
+ *sizePtr = stringPtr->allocated;
+ return objPtr->bytes;
+}
+/*
+ *---------------------------------------------------------------------------
+ *
* TclStringObjReverse --
*
* Implements the [string reverse] operation.