summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2013-01-09 12:33:45 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2013-01-09 12:33:45 (GMT)
commit769d959f080ba9349c760f556b1064c47a88b28d (patch)
tree27db300585a58a7ebc136cbaba74da3711ec9d0b /generic/tclUtil.c
parent4f51c434a64c980708d570c083a0682acebd0b7b (diff)
downloadtcl-769d959f080ba9349c760f556b1064c47a88b28d.zip
tcl-769d959f080ba9349c760f556b1064c47a88b28d.tar.gz
tcl-769d959f080ba9349c760f556b1064c47a88b28d.tar.bz2
Restore API compatibility with public Tcl_*Scan and Tcl_*Convert functions (changes in private functions are OK)
Increase LOCAL_SIZE to 64, and remove two Panic's which cannot occur any more as a result of the improvements.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c32
1 files changed, 7 insertions, 25 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index c8cb75c..c6dd464 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -872,7 +872,7 @@ Tcl_SplitList(
int
Tcl_ScanElement(
const char *src, /* String to convert to list element. */
- char *flagPtr) /* Where to store information to guide
+ int *flagPtr) /* Where to store information to guide
* Tcl_ConvertCountedElement. */
{
return Tcl_ScanCountedElement(src, -1, flagPtr);
@@ -905,7 +905,7 @@ int
Tcl_ScanCountedElement(
const char *src, /* String to convert to Tcl list element. */
int length, /* Number of bytes in src, or -1. */
- char *flagPtr) /* Where to store information to guide
+ int *flagPtr) /* Where to store information to guide
* Tcl_ConvertElement. */
{
char flags = CONVERT_ANY;
@@ -1236,7 +1236,7 @@ int
Tcl_ConvertElement(
const char *src, /* Source information for list element. */
char *dst, /* Place to put list-ified element. */
- char flags) /* Flags produced by Tcl_ScanElement. */
+ int flags) /* Flags produced by Tcl_ScanElement. */
{
return Tcl_ConvertCountedElement(src, -1, dst, flags);
}
@@ -1267,7 +1267,7 @@ Tcl_ConvertCountedElement(
register const char *src, /* Source information for list element. */
int length, /* Number of bytes in src, or -1. */
char *dst, /* Place to put list-ified element. */
- char flags) /* Flags produced by Tcl_ScanElement. */
+ int flags) /* Flags produced by Tcl_ScanElement. */
{
int numBytes = TclConvertElement(src, length, dst, flags);
dst[numBytes] = '\0';
@@ -1481,11 +1481,10 @@ Tcl_Merge(
int argc, /* How many strings to merge. */
const char *const *argv) /* Array of string values. */
{
-#define LOCAL_SIZE 20
+#define LOCAL_SIZE 64
char localFlags[LOCAL_SIZE];
int i, bytesNeeded = 0;
char *result, *dst, *flagPtr = NULL;
- const int maxFlags = UINT_MAX / sizeof(int);
/*
* Handle empty list case first, so logic of the general case can be
@@ -1504,33 +1503,16 @@ Tcl_Merge(
if (argc <= LOCAL_SIZE) {
flagPtr = localFlags;
- } else if (argc > maxFlags) {
- /*
- * We cannot allocate a large enough flag array to format this list in
- * one pass. We could imagine converting this routine to a multi-pass
- * implementation, but for sizeof(int) == 4, the limit is a max of
- * 2^30 list elements and since each element is at least one byte
- * formatted, and requires one byte space between it and the next one,
- * that a minimum space requirement of 2^31 bytes, which is already
- * INT_MAX. If we tried to format a list of > maxFlags elements, we're
- * just going to overflow the size limits on the formatted string
- * anyway, so just issue that same panic early.
- */
-
- Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
} else {
- flagPtr = ckalloc(argc * sizeof(char));
+ flagPtr = ckalloc(argc);
}
for (i = 0; i < argc; i++) {
flagPtr[i] = ( i ? TCL_DONT_QUOTE_HASH : 0 );
bytesNeeded += TclScanElement(argv[i], -1, &flagPtr[i]);
- if (bytesNeeded < 0) {
+ if ((bytesNeeded < 0) || (bytesNeeded > INT_MAX - argc + 1)) {
Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
}
}
- if (bytesNeeded > INT_MAX - argc + 1) {
- Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
- }
bytesNeeded += argc;
/*