diff options
author | dgp <dgp@users.sourceforge.net> | 2011-04-28 13:45:27 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-04-28 13:45:27 (GMT) |
commit | 319c5292645aa41b4f56539f615ba5314b27c957 (patch) | |
tree | eeb1f804e2651e52f4e17556a06117eaa660358b | |
parent | 7fe2661780c57879cdb780f89e961c8ec844ebfc (diff) | |
download | tcl-319c5292645aa41b4f56539f615ba5314b27c957.zip tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.gz tcl-319c5292645aa41b4f56539f615ba5314b27c957.tar.bz2 |
Improved reaction to out of memory.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | generic/tclStringObj.c | 8 |
2 files changed, 11 insertions, 1 deletions
@@ -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)); |