aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2003-01-07 10:06:06 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2003-01-07 10:06:06 +0000
commit00a04e2a59dfd250ceaeae09aba6f98a424984bb (patch)
tree72cc14556efaebb1afda572a9ebc23359cd6a032
parent6ada70cc9219f5e5bae78ad2bade1fecf7b20867 (diff)
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
-rw-r--r--src/Startup.c31
1 files 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;