From 00a04e2a59dfd250ceaeae09aba6f98a424984bb Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 7 Jan 2003 10:06:06 +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/IOBasic/trunk@138 b589c3ab-70e8-4b4d-a09f-cba2dd200880 --- src/Startup.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Startup.c b/src/Startup.c index 22ab17f..c27e7b5 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -101,6 +101,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) { int i; iobasicGH *myGH; + const char *my_out_dir; DECLARE_CCTK_PARAMETERS @@ -110,7 +111,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) (void) (GH + 0); /* allocate the GH extension and its components */ - myGH = (iobasicGH *) malloc (sizeof (iobasicGH)); + myGH = malloc (sizeof (iobasicGH)); if (myGH) { /* Register the IOBasic routines as output methods */ @@ -136,10 +137,9 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) i = CCTK_NumVars (); - myGH->info_reductions = (iobasic_reductionlist_t *) - calloc (2 * i, sizeof (iobasic_reductionlist_t)); + myGH->info_reductions = calloc (2 * i, sizeof (iobasic_reductionlist_t)); myGH->scalar_reductions = myGH->info_reductions + i; - myGH->outInfo_last = (int *) malloc (2 * i * sizeof (int)); + myGH->outInfo_last = malloc (2 * i * sizeof (int)); myGH->outScalar_last = myGH->outInfo_last + i; /* initialize counters for how often to do output with a value different @@ -155,17 +155,18 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) myGH->filenameListScalar = NULL; /* get the name of IOBasic'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); - myGH->out_dir = (char *) malloc (i + 2); - strcpy (myGH->out_dir, out_dir); + i = strlen (my_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; } @@ -250,8 +251,7 @@ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) optstring, CCTK_VarName (vindex)); } - list->reductions = (iobasic_reduction_t *) - malloc (sizeof (iobasic_reduction_t)); + list->reductions = malloc (sizeof (iobasic_reduction_t)); if (strncmp (CCTK_VarTypeName (CCTK_VarTypeI (vindex)), "CCTK_VARIABLE_COMPLEX", 21)) { @@ -263,8 +263,7 @@ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) { list->num_reductions = 2; list->reductions->name = strdup ("real part"); - list->reductions->next = (iobasic_reduction_t *) - malloc (sizeof (iobasic_reduction_t)); + list->reductions->next = malloc (sizeof (iobasic_reduction_t)); list->reductions->next->name = strdup ("imag part"); list->reductions->next->next = NULL; } @@ -337,7 +336,7 @@ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) /* now loop over all reduction operators */ string_start = reduction_op_list; - reduction_op = (char *) malloc (strlen (string_start) + 1); + reduction_op = malloc (strlen (string_start) + 1); while (string_start && *string_start) { /* skip leading spaces */ @@ -391,7 +390,7 @@ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) continue; } - *new_reduction = (iobasic_reduction_t *) malloc (sizeof (**new_reduction)); + *new_reduction = malloc (sizeof (**new_reduction)); (*new_reduction)->handle = reduction_handle; (*new_reduction)->name = strdup (reduction_op); (*new_reduction)->next = NULL; -- cgit v1.2.3