From e09c7776b3ee325bd972de72a641f9342f6c379a Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 20 Mar 2007 21:20:10 +0000 Subject: * generic/tclEnv.c: Some more ckalloc -> ckrealloc replacements. * generic/tclLink.c: --- ChangeLog | 5 +++++ generic/tclEnv.c | 20 ++++++-------------- generic/tclLink.c | 8 +++----- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90b52d9..cc7041f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-03-20 Don Porter + + * generic/tclEnv.c: Some more ckalloc -> ckrealloc replacements. + * generic/tclLink.c: + 2007-03-20 Kevin B. Kenny * generic/tclDate.c: Rebuilt, despite Donal Fellows's comment when diff --git a/generic/tclEnv.c b/generic/tclEnv.c index 12f4ab4..ab5a9a0 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEnv.c,v 1.29 2006/10/31 22:24:39 das Exp $ + * RCS: @(#) $Id: tclEnv.c,v 1.30 2007/03/20 21:20:12 dgp Exp $ */ #include "tclInt.h" @@ -638,7 +638,6 @@ ReplaceString( char *newStr) /* New environment string. */ { int i; - char **newCache; /* * Check to see if the old value was allocated by Tcl. If so, it needs to @@ -670,24 +669,17 @@ ReplaceString( environCache[cacheSize-1] = NULL; } } else { - int allocatedSize = (cacheSize + 5) * sizeof(char *); - /* * We need to grow the cache in order to hold the new string. */ - newCache = (char **) ckalloc((unsigned) allocatedSize); - (void) memset(newCache, (int) 0, (size_t) allocatedSize); + const int growth = 5; - if (environCache) { - memcpy((void *) newCache, (void *) environCache, - (size_t) (cacheSize * sizeof(char*))); - ckfree((char *) environCache); - } - environCache = newCache; + environCache = (char **) ckrealloc ((char *) environCache, + (cacheSize + growth) * sizeof(char *)); environCache[cacheSize] = newStr; - environCache[cacheSize+1] = NULL; - cacheSize += 5; + (void) memset(environCache+cacheSize+1, (int) 0, (size_t) (growth - 1)); + cacheSize += growth; } } diff --git a/generic/tclLink.c b/generic/tclLink.c index fec4fdb..bdfa4db 100644 --- a/generic/tclLink.c +++ b/generic/tclLink.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclLink.c,v 1.19 2007/03/03 10:04:42 dkf Exp $ + * RCS: @(#) $Id: tclLink.c,v 1.20 2007/03/20 21:20:12 dgp Exp $ */ #include "tclInt.h" @@ -518,10 +518,8 @@ LinkTraceProc( value = Tcl_GetStringFromObj(valueObj, &valueLength); valueLength++; pp = (char **) linkPtr->addr; - if (*pp != NULL) { - ckfree(*pp); - } - *pp = (char *) ckalloc((unsigned) valueLength); + + *pp = ckrealloc(*pp, valueLength); memcpy(*pp, value, (unsigned) valueLength); break; -- cgit v0.12