summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-04-28 13:45:27 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-04-28 13:45:27 (GMT)
commit319c5292645aa41b4f56539f615ba5314b27c957 (patch)
treeeeb1f804e2651e52f4e17556a06117eaa660358b
parent7fe2661780c57879cdb780f89e961c8ec844ebfc (diff)
downloadtcl-319c5292645aa41b4f56539f615ba5314b27c957.zip
tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.gz
tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.bz2
Improved reaction to out of memory.
-rw-r--r--ChangeLog4
-rw-r--r--generic/tclStringObj.c8
2 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 22fadc0..02bcdf6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-04-28 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclStringObj.c: Improved reaction to out of memory.
+
2011-04-27 Don Porter <dgp@users.sourceforge.net>
* generic/tclCmdMZ.c: TclFreeIntRep() correction & cleanup.
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 7f31fdf..0f6eff7 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -131,6 +131,8 @@ typedef struct String {
Tcl_Panic("max length for a Tcl unicode value (%d chars) exceeded", \
STRING_MAXCHARS); \
}
+#define stringAttemptAlloc(numChars) \
+ (String *) attemptckalloc((unsigned) STRING_SIZE(numChars) )
#define stringAlloc(numChars) \
(String *) ckalloc((unsigned) STRING_SIZE(numChars) )
#define stringRealloc(ptr, numChars) \
@@ -2856,7 +2858,11 @@ DupStringInternalRep(
} else {
copyMaxChars = srcStringPtr->maxChars;
}
- copyStringPtr = stringAlloc(copyMaxChars);
+ copyStringPtr = stringAttemptAlloc(copyMaxChars);
+ if (copyStringPtr == NULL) {
+ copyMaxChars = srcStringPtr->numChars;
+ copyStringPtr = stringAlloc(copyMaxChars);
+ }
copyStringPtr->maxChars = copyMaxChars;
memcpy(copyStringPtr->unicode, srcStringPtr->unicode,
srcStringPtr->numChars * sizeof(Tcl_UniChar));