summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2024-01-29 15:26:48 (GMT)
committersebres <sebres@users.sourceforge.net>2024-01-29 15:26:48 (GMT)
commitff9b361ee1cd6c83f325904f8c6d2c23dbf253cd (patch)
tree8f85bf18f3421579c02f60799d1835d4364d5e37 /generic
parent17b066864d0254d9ff42a45a3ab221693d3de664 (diff)
parentb0b50752804a4ae7921d7c6aacc089c3c756cf65 (diff)
downloadtcl-ff9b361ee1cd6c83f325904f8c6d2c23dbf253cd.zip
tcl-ff9b361ee1cd6c83f325904f8c6d2c23dbf253cd.tar.gz
tcl-ff9b361ee1cd6c83f325904f8c6d2c23dbf253cd.tar.bz2
merge 8.6
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c3
-rw-r--r--generic/tclInt.h6
-rw-r--r--generic/tclStringObj.c37
3 files changed, 41 insertions, 5 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 3b36457..7e7d88c 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -6322,8 +6322,9 @@ ReadChars(
int factor = *factorPtr;
int dstLimit = TCL_UTF_MAX - 1 + toRead * factor / UTF_EXPANSION_FACTOR;
+ if (dstLimit <= 0) dstLimit = INT_MAX; /* avoid overflow */
(void) TclGetStringFromObj(objPtr, &numBytes);
- Tcl_AppendToObj(objPtr, NULL, dstLimit);
+ TclAppendUtfToUtf(objPtr, NULL, dstLimit);
if (toRead == srcLen) {
unsigned int size;
diff --git a/generic/tclInt.h b/generic/tclInt.h
index d29ea37..73e1915 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3085,12 +3085,14 @@ struct Tcl_LoadHandle_ {
*----------------------------------------------------------------
*/
-MODULE_SCOPE void TclAppendBytesToByteArray(Tcl_Obj *objPtr,
- const unsigned char *bytes, Tcl_Size len);
MODULE_SCOPE void TclAdvanceContinuations(Tcl_Size *line, Tcl_Size **next,
int loc);
MODULE_SCOPE void TclAdvanceLines(Tcl_Size *line, const char *start,
const char *end);
+MODULE_SCOPE void TclAppendBytesToByteArray(Tcl_Obj *objPtr,
+ const unsigned char *bytes, Tcl_Size len);
+MODULE_SCOPE void TclAppendUtfToUtf(Tcl_Obj *objPtr,
+ const char *bytes, int numBytes);
MODULE_SCOPE void TclArgumentEnter(Tcl_Interp *interp,
Tcl_Obj *objv[], int objc, CmdFrame *cf);
MODULE_SCOPE void TclArgumentRelease(Tcl_Interp *interp,
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 3afee99..bc2d4e9 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1963,7 +1963,7 @@ AppendUnicodeToUtfRep(
* None.
*
* Side effects:
- * objPtr's internal rep is reallocated.
+ * objPtr's internal rep is reallocated and string rep is cleaned.
*
*----------------------------------------------------------------------
*/
@@ -1999,7 +1999,7 @@ AppendUtfToUnicodeRep(
* None.
*
* Side effects:
- * objPtr's internal rep is reallocated.
+ * objPtr's string rep is reallocated (by TCL STRING GROWTH ALGORITHM).
*
*----------------------------------------------------------------------
*/
@@ -2079,6 +2079,39 @@ AppendUtfToUtfRep(
/*
*----------------------------------------------------------------------
*
+ * TclAppendUtfToUtf --
+ *
+ * This function appends "numBytes" bytes of "bytes" to the UTF string
+ * rep of "objPtr" (objPtr's internal rep converted to string on demand).
+ * numBytes must be non-negative.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * objPtr's string rep is reallocated (by TCL STRING GROWTH ALGORITHM).
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TclAppendUtfToUtf(
+ Tcl_Obj *objPtr, /* Points to the object to append to. */
+ const char *bytes, /* String to append (or NULL to enlarge buffer). */
+ Tcl_Size numBytes) /* Number of bytes of "bytes" to append. */
+{
+ if (Tcl_IsShared(objPtr)) {
+ Tcl_Panic("%s called with shared object", "TclAppendUtfToUtf");
+ }
+
+ SetStringFromAny(NULL, objPtr);
+
+ AppendUtfToUtfRep(objPtr, bytes, numBytes);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_AppendStringsToObjVA --
*
* This function appends one or more null-terminated strings to an