aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-07-04 11:59:11 +0000
committertradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-07-04 11:59:11 +0000
commit3f04cb7e576055fa700dff19076c78647b8f151e (patch)
treedf0dd904085c78cf453392f35b9f824510bcf55d
parent04520bcea06b995a3c7f3be120cbc08f5034374c (diff)
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
-rw-r--r--src/CheckpointRecovery.c11
1 files 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,