From 2dd4e31b8191a6d65f74126ff3d04d88164cf5aa Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 7 Jan 2003 10:04:27 +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/CactusBase/IOASCII/trunk@139 94b1c47f-dcfd-45ef-a468-0854c0e9e350 --- src/Startup.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Startup.c b/src/Startup.c index 3de9bea..05d16a8 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -28,21 +28,24 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Startup_c) ********************************************************************/ #define CREATE_OUTDIR(method, dir) \ { \ + const char *_dir = dir; \ + \ + \ /* check whether "dir" was set; if not default to "IO::out_dir" */ \ - if (*dir == 0) \ + if (*_dir == 0) \ { \ - dir = out_dir; \ + _dir = out_dir; \ } \ \ /* omit the directory name if it's the current working dir */ \ - if (strcmp (dir, ".") == 0) \ + if (strcmp (_dir, ".") == 0) \ { \ myGH->dir = strdup (""); \ } \ else \ { \ - myGH->dir = (char *) malloc (strlen (dir) + 2); \ - sprintf (myGH->dir, "%s/", dir); \ + myGH->dir = malloc (strlen (_dir) + 2); \ + sprintf (myGH->dir, "%s/", _dir); \ } \ \ /* create the directory */ \ @@ -143,7 +146,7 @@ static void *IOASCII_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) (void) (GH + 0); /* allocate the GH extension and its components */ - myGH = (asciiioGH *) malloc (sizeof (asciiioGH)); + myGH = malloc (sizeof (asciiioGH)); if (! myGH) { CCTK_WARN (0, "IOASCII_SetupGH: Unable to allocate memory for GH"); @@ -181,12 +184,12 @@ static void *IOASCII_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) } numvars = CCTK_NumVars (); - myGH->out1D_every = (CCTK_INT *) malloc (numvars * sizeof (CCTK_INT)); - myGH->out2D_every = (CCTK_INT *) malloc (numvars * sizeof (CCTK_INT)); - myGH->out3D_every = (CCTK_INT *) malloc (numvars * sizeof (CCTK_INT)); - myGH->out1D_last = (int *) malloc (numvars * sizeof (int)); - myGH->out2D_last = (int *) malloc (numvars * sizeof (int)); - myGH->out3D_last = (int *) malloc (numvars * sizeof (int)); + myGH->out1D_every = malloc (numvars * sizeof (CCTK_INT)); + myGH->out2D_every = malloc (numvars * sizeof (CCTK_INT)); + myGH->out3D_every = malloc (numvars * sizeof (CCTK_INT)); + myGH->out1D_last = malloc (numvars * sizeof (int)); + myGH->out2D_last = malloc (numvars * sizeof (int)); + myGH->out3D_last = malloc (numvars * sizeof (int)); for (i = 0; i < numvars; i++) { -- cgit v1.2.3