summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
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 /generic/tclStringObj.c
parent7fe2661780c57879cdb780f89e961c8ec844ebfc (diff)
downloadtcl-319c5292645aa41b4f56539f615ba5314b27c957.zip
tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.gz
tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.bz2
Improved reaction to out of memory.
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c8
1 files changed, 7 insertions, 1 deletions
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));