From 3f04cb7e576055fa700dff19076c78647b8f151e Mon Sep 17 00:00:00 2001 From: tradke Date: Thu, 4 Jul 2002 11:59:11 +0000 Subject: Fixed allocation of string buffer in IOUtil_GetAllParameters(). With the old scheme it might have allocated not enough bytes for very large parameter values. This closes PR CactusBase/1115. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@174 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a --- src/CheckpointRecovery.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c index 9345da5..8de6178 100644 --- a/src/CheckpointRecovery.c +++ b/src/CheckpointRecovery.c @@ -745,7 +745,6 @@ char *IOUtil_GetAllParameters (const cGH *GH, int all) char *param, *value, *tmp, *retval; const char *thorn; const cParamData *pdata; -#define BUFFER_INCREMENT 1024 DECLARE_CCTK_PARAMETERS @@ -753,7 +752,8 @@ char *IOUtil_GetAllParameters (const cGH *GH, int all) GH = GH; retval = NULL; - current_len = max_len = 0; + current_len = 0; + max_len = 1; /* loop over all thorns */ for (i = CCTK_NumCompiledThorns () - 1; i >= 0; i--) @@ -786,7 +786,12 @@ char *IOUtil_GetAllParameters (const cGH *GH, int all) add_len = strlen (param) + strlen (value) + 5; if (current_len + add_len >= max_len) { - tmp = (char *) realloc (retval, max_len += BUFFER_INCREMENT); + /* double new buffer length until buffer is large enough */ + while (current_len + add_len >= max_len) + { + max_len *= 2; + } + tmp = (char *) realloc (retval, max_len); if (! tmp) { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, -- cgit v1.2.3