From 8a5ec0b1c2630994818eb83081b9acc7a4f279be Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 7 Jan 2003 10:07:36 +0000 Subject: Copy pointer to string parameter into local variable before modifying it. This prevents future problems when string parameter pointer will be made read-only. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@153 4825ed28-b72c-4eae-9704-e50c059e567d --- src/Startup.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Startup.c b/src/Startup.c index 8897925..33503f1 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -101,6 +101,7 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH) int i, numvars; ioHDF5GH *myGH; const ioGH *ioUtilGH; + const char *my_out_dir; const char *timer_names[4] = {"IOHDF5 time to dump parameters", "IOHDF5 time to dump variables", "IOHDF5 total time to checkpoint", @@ -127,36 +128,36 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH) /* allocate a new GH extension structure */ numvars = CCTK_NumVars (); - myGH = (ioHDF5GH *) malloc (sizeof (ioHDF5GH)); - myGH->out_last = (int *) malloc (numvars * sizeof (int)); - myGH->requests = (ioRequest **) calloc (numvars, sizeof (ioRequest *)); - myGH->cp_filename_list = (char **) calloc (abs (checkpoint_keep), - sizeof (char *)); + myGH = malloc (sizeof (ioHDF5GH)); + myGH->out_last = malloc (numvars * sizeof (int)); + myGH->requests = calloc (numvars, sizeof (ioRequest *)); + myGH->cp_filename_list = calloc (abs (checkpoint_keep), sizeof (char *)); myGH->cp_filename_index = 0; myGH->out_vars = strdup (""); myGH->out_every_default = out_every - 1; /* get the name of IOHDF5's output directory */ - if (*out_dir == 0) + my_out_dir = out_dir; + if (*my_out_dir == 0) { - out_dir = io_out_dir; + my_out_dir = io_out_dir; } /* skip the directory pathname if output goes into current directory */ - if (strcmp (out_dir, ".")) + if (strcmp (my_out_dir, ".")) { - i = strlen (out_dir); - if (CCTK_Equals (out_mode, "onefile") || ! strstr (out_dir, "%u")) + i = strlen (my_out_dir); + if (CCTK_Equals (out_mode, "onefile") || ! strstr (my_out_dir, "%u")) { - myGH->out_dir = (char *) malloc (i + 2); - strcpy (myGH->out_dir, out_dir); + myGH->out_dir = malloc (i + 2); + strcpy (myGH->out_dir, my_out_dir); myGH->out_dir[i] = '/'; myGH->out_dir[i+1] = 0; } else { - myGH->out_dir = (char *) malloc (i + 20); - sprintf (myGH->out_dir, out_dir, CCTK_MyProc (GH)); + myGH->out_dir = malloc (i + 20); + sprintf (myGH->out_dir, my_out_dir, CCTK_MyProc (GH)); strcat (myGH->out_dir, "/"); } } @@ -166,7 +167,7 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH) } /* create the output directory */ - ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); + ioUtilGH = CCTK_GHExtension (GH, "IO"); i = IOUtil_CreateDirectory (GH, myGH->out_dir, ! CCTK_Equals (out_mode, "onefile"), ioUtilGH->ioproc); -- cgit v1.2.3